Python Operator Precedence
Introduction to Programming
and Algorithm Design (COP-1000)

This page lists Python operators in order of their precedence (highest
to lowest). Operators in the same box group left to right (except for
comparisons and tests, which all have the same precedence and chain from
left to right and exponentiation, which groups from right to left).
|
Operator
|
Description |
| () |
Parentheses (grouping) |
| f(args...) |
Function call |
| x[index:index] |
Slicing |
| x[index] |
Subscription |
|
x.attribute |
Attribute reference |
| ** |
Exponentiation |
| ~x |
Bitwise not |
| +x, -x |
Positive, negative |
| *, /,
% |
Multiplication, division, remainder |
| +,
- |
Addition, subtraction |
| <<,
>> |
Bitwise shifts |
| & |
Bitwise AND |
| ^ |
Bitwise XOR |
| | |
Bitwise OR |
<, <=,
>, >=,
<>, !=, == |
Comparisons |
| is, is not |
Identity tests |
| in, not in |
Membership tests |
| not x |
Boolean NOT |
| and |
Boolean AND |
| or |
Boolean OR |
| lambda |
Lambda expression |
|