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?

19th Aug 2023, 3:42 PM
Vidya gupta
Vidya gupta - avatar
5 Respostas
+ 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`
19th Aug 2023, 4:19 PM
Darpan kesharwani🇮🇳[Inactive📚]
Darpan kesharwani🇮🇳[Inactive📚] - avatar
+ 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.
19th Aug 2023, 3:54 PM
Marcos Chamosa Rodríguez
Marcos Chamosa Rodríguez - avatar
+ 1
i am learning it after a long gap so may be i have forgotten
19th Aug 2023, 3:57 PM
Vidya gupta
Vidya gupta - avatar
0
ok
19th Aug 2023, 3:57 PM
Vidya gupta
Vidya gupta - avatar