0

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 ? """

6th Oct 2019, 9:06 AM
Zahid Khan
Zahid Khan - avatar
3 Antworten
+ 4
10<9 is evaluated second because thats the fixed order of precedence(i.e.,preference) for the < operators.
6th Oct 2019, 9:14 AM
Mohamed Arshad
Mohamed Arshad - avatar
+ 4
Actually it is non associative. This is a Python feature called chained comparisons https://docs.python.org/3/reference/expressions.html#comparisons
6th Oct 2019, 9:14 AM
jtrh
jtrh - avatar
0
Thanks everyone i got it
6th Oct 2019, 12:28 PM
Zahid Khan
Zahid Khan - avatar