0
Why is it okay to be false one way but true the other way using "or"
print(2 == (2 or 1)) True print(False == (False or True)) False "I would thought print(False == (False or True)) would be True" "Thanks for your help" "DJ"
6 Answers
+ 7
a or b => a if a else b
a and b => b if a else a
so
2 == (2 or 1) #a is True so returns a
2 == 2
True
False == (False or True) #a is False so returns b
False == True
False
+ 6
Just so you know (2 or 1) is 2 while (1 or 2) is 1 so print(2 == (1 or 2)) is false.
+ 3
Dj Pratt if I asked you a math question, what is 2+2 and you weren't sure of the answer but you knew it was 3 or 4, you would be right because the answer is 3 or 4 in this case 4.
I hope this helps you to understand, I was confused at that as well when I learned it.
+ 3
John Wells whoaa!! I didn't know that. Really cool.
+ 2
Dj Pratt . When you have False == (False or True) you are not cheking with False equals False or equals True you are checking with result of operation X or Y is true.
So in math True or False equals True.
So you kind writting False == True.
That's why is False
+ 1
I was shocked the original gave true so I coded prints of both versions to find the result is the first number. In other languages, (2 or 1) would give true so 2 == true would be false.