0
Python Query
Why if a=True or False print(a) output will be false but if doorlocked=True Lights=False print(doorlocked or Lights) output is true WHYYY?
5 odpowiedzi
+ 5
Vidya gupta
In first case:-
`a=True or False
Print(a)`
In this case of `a = True or False`,
the "or" operator evaluates the expression from left to right.
Since the first value encountered is "True", it immediately returns "True" without evaluating the second operand.
Hence answer:True
___________________
In second case:
`doorlocked=True
Lights=False
print(doorlocked or Lights)`
In this case of `doorlocked or Lights`. the "or" operator again evaluates the expression from left to right.
In this case, the first operand is "True" and the "or" operator immediately returns "True" without evaluating the second operand.
Hence Answer:true
#quick quide about `or`operator..
The "or" operator is a logical operator . It is used to combine two or more conditions and returns "True" if at least one of the conditions is true.
#Here's how the "or" operator works:
True or False: evaluates `True`
False or True: evaluate`True`
False or False: evaluates `False`
+ 1
You must have made a mistake somewhere. Both would return True. 'or' always returns true so long as one of the operands is True.
+ 1
i am learning it after a long gap so may be i have forgotten
0
ok