運算子優先順序決定運算式中運算的群組順序。優先順序高的運算子優先被計算。例如 7 + 3 * 2 中,* 優先於 +,故結果為 13 而非 20。

| 優先順序 | 運算子 | 說明 |
|---|---|---|
| 1 | ** | 冪次 |
| 2 | ~ + - | 按位取反、正負號 |
| 3 | * / % // | 乘、除、取餘、整除 |
| 4 | + - | 加、減 |
| 5 | > > < < | 位移 |
| 6 | & | 按位 AND |
| 7 | ^ | | 按位 XOR、OR |
| 8 | <= < > >= | 比較運算子 |
| 9 | == != | 等值比較 |
| 10 | = %= /= //= -= += *= **= | 指派運算子 |
| 11 | is is not | 身分運算子 |
| 12 | in not in | 成員運算子 |
| 13 | not and or | 邏輯運算子 |
#!/usr/bin/python
a = 20
b = 10
c = 15
d = 5
e = 0
e = (a + b) * c / d # (30 * 15) / 5 = 90
print("Value of (a + b) * c / d is", e)
e = ((a + b) * c) / d # 同上,括號明確化
print("Value of ((a + b) * c) / d is", e)
e = (a + b) * (c / d) # 30 * (15/5) = 90
print("Value of (a + b) * (c / d) is", e)
e = a + (b * c) / d # 20 + (150/5) = 50
print("Value of a + (b * c) / d is", e)
Value of (a + b) * c / d is 90
Value of ((a + b) * c) / d is 90
Value of (a + b) * (c / d) is 90
Value of a + (b * c) / d is 50
() 可強制改變優先順序,提升可讀性。** 為右結合)。a < b < c 等價於 a < b and b < c。