Operator Precedence and Associativity in Python
Operator Precedence and Associativity in Python
Subscription,
2 x[index], x[index:index] Left to right
slicing
Await
3 await x N/A
expression
Positive,
5 +x, -x, ~x negative, bitwise Right to left
NOT
Multiplication,
matrix, division,
6 *, @, /, //, % Left to right
floor division,
remainder
Addition and
7 +, – Left to right
subtraction
Comparisons,
in, not in, is, is membership
12 Left to Right
not, <, <=, >, >=, !=, == tests, identity
tests
Conditional
16 if-else Right to left
expression
Lambda
17 lambda N/A
expression
Assignment
expression
18 := Right to left
(walrus
operator)