Can someone explain how these results are possible (python 2.6):
>>> 1<3>2
True
>>> (1<3)>2
False
>>> 1<(3>2)
False
I would think that one of the last two would match the first one, but apparently the operators in the first statement is somehow linked?!
Your first example shows comparison chaining.
1<3>2means1<3 and 3>2(except each expression is evaluated only once). This applies to all comparison operators in Python.Your second two examples force one comparison to be evaluated first, resulting in a boolean value which is then compared with the remaining integer.