Python Operator Precedence

Operations are prioritized from top to bottom, with higher priority operations at the top. Calculations proceed from left to right, so if an expression contains operators of the same precedence, the leftmost operator is executed first.

The exponentiation operator is an exception. When using two ** operators, the right one is executed before the left.

OperatorsDescription
()Parentheses
**Exponentiation
+x, -x, ~xUnary plus, minus, and bitwise negation
*, /, //, %Multiplication, division, floor division, remainder
+, -Addition and subtraction
<<, >>Bitwise shifts
&Bitwise AND
^Bitwise exclusive OR (XOR)
|Bitwise OR
==, !=, >, >=, <, <=, is, is not, in, not inComparison, identity checks, membership tests
notLogical NOT
andLogical AND
orLogical OR