- 1

1 < -1 == 3 > 4 evaluates to False. Why?

It must evaluate to true according to operator precedence. As 1<-1 evaluates to false and 3 > 4 also evaluates to false. Then False == False is True. But why does it evaluate to Fasle?

12th Jan 2021, 5:12 AM
Mousin Ahanger
Mousin Ahanger - avatar
2 Answers
+ 6
Python allows chaining of logical operators. So 1 < 3 > 2 in other languages will be true > 2, which is false But in Python, it will be 1 < 3 and 3 > 2, which is True Similarly, 1 < -1 == 3 > 4 is equivalent to 1 < -1 and -1 == 3 and 3 > 4, which is False
12th Jan 2021, 5:21 AM
XXX
XXX - avatar
+ 1
As per the explanation of XXX, here is another way of looking it. print((1 < -1) == (3 > 4)) # true
12th Jan 2021, 6:56 AM
Rik Wittkopp
Rik Wittkopp - avatar