6

Consider this statement:

> False == False in [False]
True

However:

> (False == False) in [False]
False
> False == (False in [False])
False

It is incredible. What's the reason and the interpretation?

1 Answers1

5

dis.dis to the rescue and a bit of my interpretation.

Anyway, it looks like this. Consider three expression X, Y, Z and two operators O1, O2. Then

X O1 Y O2 Z

is equivalent to

(X O1 Y) and (Y O2 Z)

as can be seen by

a < b < c

example. I find this behaviour very counterintuitive.

And the docs:

Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false).

Note that in is a comparison operator.

freakish
  • 54,167
  • 9
  • 132
  • 169