Operators with the highest precedence are placed on the top:
Operator |
Description |
( ) |
Parentheses |
x[index],x[index1:index2],f(arg...),x.attribute |
Subscription, slicing, call, and attribute reference |
** |
Exponentiation |
+x, -x, ~x |
Positive, negative, and bitwise NOT |
*, /, % |
Multiplication, division, and remainder |
+, - |
Addition and subtraction |
<<, >> |
Shifts |
& |
Bitwise AND |
^ |
Bitwise XOR |
| |
Bitwise OR |
in, not in, is, is not, <, <=, >, >=, !=, == |
Comparisons, including membership tests and identity tests |
not x |
Boolean NOT |
and |
Boolean AND |
or |
Boolean OR |
if...else |
Conditional expression |
lambda |
Lambda expression |
Operators that have the same precedence are evaluated from left to right, except for comparisons and exponentiation. Comparisons can be chained arbitrarily.