0

Why is it?

Can anyone explain why this is happening print( 5 == (5 or 6) ) True print(False == (False or True)) False

6th Oct 2020, 3:21 PM
Gh Hoop
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
6th Oct 2020, 3:38 PM
Abhay
Abhay - avatar
+ 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.
6th Oct 2020, 3:52 PM
Russ
Russ - avatar
+ 3
Look at the logic truth table for 'or'.
8th Oct 2020, 2:00 AM
Sonic
Sonic - avatar
+ 1
I dont have problem with first code But second, why False or True, it chose True?
6th Oct 2020, 3:42 PM
Gh Hoop
0
What about code below that? False equals to False or True and it should be True.
6th Oct 2020, 3:38 PM
Gh Hoop
0
Gh Hoop no. False == (False or True) False == True False Or returns true even if either one of the value is true
6th Oct 2020, 3:55 PM
‎ ‏‏‎Anonymous Guy
- 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
6th Oct 2020, 3:32 PM
Kaushal Gunawat
Kaushal Gunawat - avatar