 |
 |
 |
Python 语言参考手册Python Reference Manual |
 |
 |
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.
对于某些运算符有特殊的规则(例如, "
 |
 |
 |
Python 语言参考手册Python Reference Manual |
 |
 |
版本 2.3.3, 文件最后更新时间 译文最后修改: 二月 18, 2004.