Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The == (equality) and in (membership) operators have the same precedence level, which is lower than most of the arithmetic and bitwise operators.

They associate to the left, meaning that if there are multiple comparisons of equal or lower precedence in a single expression, they are evaluated from left to right.

For example, the expression 1 == 2 in [3, 4] is equivalent to (1 == 2) and (2 in [3, 4]), which evaluates to False.

The expressions 1 in [1, 2] == True and 1 in [1, 2] == False are both invalid syntax since they are ambiguous and do not have a well-defined order of evaluation.