Operator Precedence
The following table summarizes the operator precedence in Python, from highest precedence (most binding) to lowest precedence (least binding) [docg]. Operators in the same cell have the same precedence (use left-to-right precedence).
Operator |
Description |
---|---|
|
Binding or parenthesized expression, list display, dictionary display, set display |
|
Subscription, slicing, call, attribute reference |
|
Await expression |
|
Exponentiation [1] |
|
Positive, negative, bitwise NOT |
|
Multiplication, matrix multiplication, division, floor division, remainder [2] |
|
Addition and subtraction |
|
Shifts |
|
Bitwise AND |
|
Bitwise XOR |
|
Bitwise OR |
|
Comparisons, including membership tests and identity tests |
|
Boolean NOT |
|
Boolean AND |
|
Boolean OR |
|
Conditional expression (ternary |
|
Lambda expression |
|
Assignment expression |