5.14 总结 Summary

The following table summarizes the operator precedences in Python, from lowest precedence (least binding) to highest precedence (most binding). Operators in the same box have the same precedence. Unless the syntax is explicitly given, operators are binary. Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right -- see section 5.9 - and exponentiation, which groups from right to left).

下表总结了Python中运算符的优先级, 从低优先级(弱捆绑)到高优先级(强捆绑), 在同一格子中的运算符具有相同的优先级.如果没有特殊的句法指定, 运算符是二元的. 同一格子内的运算符都从左至右结合(比较运算符是个例外, 它们可以从左到右连接起来 -- 见上文, 并且幂运算符也是从左至右结合).

Operator  Description 
lambda Lambda表达式 Lambda expression
or 布尔OR Boolean OR
and 布尔AND Boolean AND
not x 布尔NOT Boolean NOT
in, not in 成员测试 Membership tests
is, is not 标识测试 Identity tests
<, <=, >, >=, <>, !=, == 比较 Comparisons
| 比特级OR Bitwise OR
^ 比特级XOR Bitwise XOR
& 比特级AND Bitwise AND
<<, >> 移位 Shifts
+, - 加减 Addition and subtraction
*, /, % 乘,除,取余 Multiplication, division, remainder
+x, -x 正运算,负运算 Positive, negative
~x 比特级not Bitwise not
** 幂 Exponentiation
x.attribute 属性引用 Attribute reference
x[index] 下标 Subscription
x[index:index] 片断 Slicing
f(arguments...) 函数调用 Function call
(expressions...) 表达式分组或元组 Binding or tuple display
[expressions...] 列表 List display
{key:datum...} 字典 Dictionary display
`expressions...` 串转换 String conversion