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


5. 表达式 Expressions

This chapter explains the meaning of the elements of expressions in Python.

本章描述了Python中表达式的组成元素的含义。

Syntax Notes: In this and the following chapters, extended BNFnotation will be used to describe syntax, not lexical analysis. When (one alternative of) a syntax rule has the form

句法注意:在本章和之后的章节中,描述句法时使用与词法分析时不同的扩展BNF记法。当某个句法规则(可能是可选的)具有如下形式

name  ::=  othername

and no semantics are given, the semantics of this form of name are the same as for othername.

并且未给出特定语义时,name的这种形式规则的意义就是其与othername含义相同。



5.1 数值型间的转换 Arithmetic conversions

When a description of an arithmetic operator below uses the phrase ``the numeric arguments are converted to a common type,'' the arguments are coerced using the coercion rules listed at the end of chapter 3. If both arguments are standard numeric types, the following coercions are applied:

当用以下短语"数值型参数转换为通用类型"描述数值型操作数时, 参数使用第三章中结尾处的强制规则进行强制转换.如果两个参数都属于标准数值型的, 就使用以下的强制规则:

  • If either argument is a complex number, the other is converted to complex; 如果其中一个参数是复数, 另一个也要转换成复数;
  • otherwise, if either argument is a floating point number, the other is converted to floating point; 否则, 如果其中一个参数是浮点数, 另一个也要转换成浮点数;
  • otherwise, if either argument is a long integer, the other is converted to long integer; 否则, 如果其中一个参数是长整数, 另一个也要转换成长整数;
  • otherwise, both must be plain integers and no conversion is necessary. 否则, 两个都是普通整数, 不需要转换.

Some additional rules apply for certain operators (e.g., a string left argument to the `%' operator). Extensions can define their own coercions.

对于某些运算符有特殊的规则(例如, "


字数:1579    最后更新:8个月以前 [03-15 20:46]月落晨星 修改
本页编辑者:月落晨星  
[前一页]:4.2 异常 Exceptions  [后一页]:5.2 原子 Atoms
[在本页中加入书签] [收藏本书] [推荐本书]
  17xie论坛 > 本书讨论区 > 本页评论   (共0条)
发表评论

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

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