0
Why is it?
Can anyone explain why this is happening print( 5 == (5 or 6) ) True print(False == (False or True)) False
7 ответов
+ 7
Expression in brackets is always evaluted first so in first statement
(5 or 6) results in 5 as "or" operator only cares about if first value is 0 or >=1 and if it is 0 it moves to next number but since 5 is greater than 0 it returns it without checking for 6
So now you have 5==5
In second statement False or True returns True
And False==True is False
+ 4
Gh Hoop The purpose of the "or" operator is to determine if either of its operands is True (or evaluates to True). In the case of 5 or 6, since its first operand (5) evaluates to True (because it is non-zero), it returns that (i.e. 5). When it is False or True, since False is False (obviously), it goes to the second operand which is True. When that happens it returns True.
+ 3
Look at the logic truth table for 'or'.
+ 1
I dont have problem with first code
But second, why False or True, it chose True?
0
What about code below that?
False equals to False or True and it should be True.
0
Gh Hoop no.
False == (False or True)
False == True
False
Or returns true even if either one of the value is true
- 2
In the code it is written that if 5 equals to 5 or 6 answer is true and cause 5 equals to 5 is true