Python's operators are shown here from highest precedence to lowest, with a ruled line separating groups of operators with equal precedence:
Table 6. Python operator precedence
(
| Parenthesized expression or tuple. |
[
| List. |
{
| Dictionary or set. |
`...`
| Convert to string representation. |
| Attribute reference. |
| Subscript or slice; see Section 8.1, “Operations common to all the sequence types”. |
|
Call function f.
|
|
x to the y power.
|
-
| Negation. |
~
| Bitwise not (one's complement). |
| Multiplication. |
,
|
Division. The “//” form
discards the fraction from the result. For example,
“13.9//5.0” returns the
value 2.0.
|
|
Modulo (remainder of x/y).
|
| Addition, concatenation. |
| Subtraction. |
|
x shifted left ybits.
|
|
x shifted right
ybits.
|
| Bitwise and. |
| Bitwise exclusive or. |
| Bitwise or. |
,
,
,
,
,
| Comparisons. These operators are all predicates; see Section 19.1, “What is a predicate?”. |
,
| Test for membership. |
,
| Test for identity. |
not
| Boolean “not.” |
| Boolean “and.” |
| Boolean “or.” |