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

(expressions...), [expressions...], {key: value...}, {expressions...}

Binding or parenthesized expression, list display, dictionary display, set display

x[index], x[index:index], x(arguments...), x.attribute

Subscription, slicing, call, attribute reference

await x

Await expression

**

Exponentiation [1]

+x, -x, ~x

Positive, negative, bitwise NOT

*, @, /, //, %

Multiplication, matrix multiplication, division, floor division, remainder [2]

+, -

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 (ternary if)

lambda

Lambda expression

=, :=

Assignment expression