1.0 KiB
Comparisons
Unlike C, all comparison operations in Python have the same priority, which is lower than any arithmetic, shift, or bitwise operation. Also, unlike C, expressions like a < b < c have the conventional mathematical interpretation:
comparison ::= or_expr (comp_operator or_expr)*
comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!="
| "is" ["not"] | ["not"] "in"
Comparisons produce boolean values: True or False.
Comparisons can be arbitrarily chained, e.g., x < y <= z is equivalent to x < y and y <= z , except that y is evaluated only once.
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.
Note that a op1 b op2 c does not imply any comparison between a and c , so, for example, x < y > z is perfectly legal.