Running this in the REPL gives me
>>> 1 == 2 == 2
False
Which surprised me, in C this would evaluate to 1. I expected the right-hand side to evaluate to True
and 1 == True
is True
in Python. For example, this evaluates as I would expect:
>>> 1 == (2 == 2)
True
How is Python parsing and evaluating the first expression? This, evaluates the same way but this is what I would expect because ==
is right-associative and would evaluate to 0 in C
>>> 2 == 2 == 1
False