How does Python parse the first of the following three expressions? (I expected it to be the same as the second, since ==
and in
have the same precedence.)
>>> 1 == 0 in (0,1), (1==0) in (0,1), 1 == (0 in (0,1))
(False, True, True)
How does Python parse the first of the following three expressions? (I expected it to be the same as the second, since ==
and in
have the same precedence.)
>>> 1 == 0 in (0,1), (1==0) in (0,1), 1 == (0 in (0,1))
(False, True, True)
See the documentation of comparison operators: they are chained rather than grouped. So 1 == 0 in (0,1)
is equivalent to (1==0) and (0 in (0,1))
, which is obviously false.