17xie > Python 语言参考手册 > 5.12 表达式表 Expression lists
背景:                 
[本书目录] [图书首页] [本书讨论区]  
链接地址:http://www.17xie.com/read-37448.html    注册17xie 一起来写书 实现您的出书梦想!


5.12 表达式表 Expression lists

expression_list  ::=  expression ( "," expression )* [","]
Download entire grammar as text.

An expression list containing at least one comma yields a tuple. The length of the tuple is the number of expressions in the list. The expressions are evaluated from left to right.

一个表达式表是一个包括至少一个逗号的元组, 它的长是表中表达式的个数.其中表达式从左到右按顺序计算.

The trailing comma is required only to create a single tuple (a.k.a. a singleton); it is optional in all other cases. A single expression without a trailing comma doesn't create a tuple, but rather yields the value of that expression. (To create an empty tuple, use an empty pair of parentheses: ().)

最后的逗号仅仅在创建单元素元组(又称为"独元")时才需要; 在其它情况下, 它是可选的. 一个没有后缀逗号的表达式不会创建元组, 但仍会计算该表达式的值.(可以使用一对空括号() 创建一个空元组).



5.13 Evaluation order

Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side.

In the following lines, expressions will be evaluated in the arithmetic order of their suffixes:

expr1, expr2, expr3, expr4
(expr1, expr2, expr3, expr4)
{expr1: expr2, expr3: expr4}
expr1 + expr2 * (expr3 - expr4)
func(expr1, expr2, *expr3, **expr4)
expr3, expr4 = expr1, expr2

 


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

字数:2769    最后更新:8个月以前 [03-15 21:06]月落晨星 修改
本页编辑者:月落晨星  
[前一页]:5.10 布尔运算 Boolea…  [后一页]:6. 简单语句 Simple s…
[在本页中加入书签] [收藏本书] [推荐本书]
  17xie论坛 > 本书讨论区 > 本页评论   (共0条)
发表评论

用户名称 匿名发表
评论内容
验证码

关于我们 | 版权声明 | 免责声明 | 诚聘英才 | 联系我们 | 合作伙伴 | 友情链接 | 广告合作 | 提交意见
Copyright © 2007 17xie.com 互联网协同写书平台 京ICP备08002671号