why print(2<10<9) evaluates to False | Sololearn: Learn to code for FREE!


why print(2<10<9) evaluates to False

print(2<10<9) print(True<9) """ Output: False True """ """ Less operator associativity is from left to right. As per this rule, 2<10 is evaluated first and should give True then the result of above should have been evaluated second i.e True <9 but actually 10<9 is evaluated second why ? """

10/6/2019 9:06:32 AM

Zahid Khan

4 Answers

New Answer


2 < 10 < 9 is non associative operation and is evaluated as 2 < 10 and 10 < 9 lhs is True and rhs is False but due to "and" (logical and) the overall result is False


10<9 is evaluated second because thats the fixed order of precedence(i.e.,preference) for the < operators.


Actually it is non associative. This is a Python feature called chained comparisons https://docs.python.org/3/reference/expressions.html#comparisons


Thanks everyone i got it