+ 1

Why does the first line below output False but the second line below output True? print(False == (False or True)) print("spam" == ("spam" or "eggs"))

Boolean question

4th May 2017, 12:49 PM
elizabeth
2 Antworten
+ 8
The first line chooses over False or True the answer is always True since anything that is not None or False is True, So False == True = False The second one chooses over spam or eggs since it said "spam" == ("spam" or "eggs") it chooses the one the same to the left hand operator.
4th May 2017, 1:05 PM
Complex
Complex - avatar
+ 7
If the or operator finds a truthy value in left side then it immoderately return it and doesn't read the right side code. If left side doesn't contain truthy value then it will look for in right side. In short, or operator returns the very first truthy value it finds. False or True = True "spam" or "eggs" = "spam" so, False == True returns False and "spam" == "spam" returns True Hope it is clear now
4th May 2017, 1:28 PM
Apel Mahmod
Apel Mahmod - avatar