in
and ==
have the same precedence, but looking at the python language Comparisons section, these operations are chained so that an expression such as a < b < c
work in the mathematical sense, unlike languages such as C.
Formally, if a, b, c, …, y, z are expressions and op1, op2, …, opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once.
Thus x in L == u
is equivalent to x in L and L == u
. Python does not use the result of x in L
in the next comparison. In fact, if x
is not in L
, python would short-circuit immediately and would not even execute the ==
comparison.
When you group with parenthesis, these operations are no longer chained. x in L
is evaluated as an expression and its result is used in the next comparison.