optimized translation index.md (#21189)

improved readability. Corrected some web translation mistakes
pull/26386/head^2
zd6 2018-12-26 16:06:55 -08:00 committed by Jingyi Ding
parent 191bc0492a
commit 3131241bdc
1 changed files with 18 additions and 18 deletions

View File

@ -4,42 +4,42 @@ localeTitle: Python数值运算
--- ---
[Python文档 - 数字操作](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) [Python文档 - 数字操作](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)
Python完全支持混合算术当二进制算术运算符具有不同数值类型的操作数时具有“较窄”类型的操作数被扩展为另一个的操作数,其中整数比浮点更窄,这比复数更窄。混合类型数字之间的比较使用相同的规则。 [2\]构造函数intfloat和complex可用于生成特定类型的数字。](https://docs.python.org/3/library/functions.html#abs) Python完全支持混合变量类型的算术:当二进制算术运算符具有不同数值类型的操作数时,具有“较局限”类型的操作数被扩展为另一个的操作数,其中整数比浮点更局限,这比复数更局限。混合变量类型的数字之间的比较运算使用相同的规则。 [2\]构造函数intfloat和complex可用于生成特定类型的数字。](https://docs.python.org/3/library/functions.html#abs)
所有数字类型(复除外)都支持以下操作,按升序优先级排序(所有数字操作的优先级都高于比较操作): 所有数字类型(复除外)都支持以下操作,按升序优先级排序(所有数字操作的优先级都高于比较操作):
操作|结果|备注|完整的文档 操作|结果|备注|完整的文档
\----------------- | -------------------------------------------------- ------------------------- | ------ | -------------------------------------------------- --------------------- \----------------- | -------------------------------------------------- ------------------------- | ------ | -------------------------------------------------- ---------------------
`x + y` | x和y的和| | `x + y` | x和y的和| |
`x - y` | x和y的差| | `x - y` | x和y的差| |
`x * y` | x和y的积| | `x * y` | x和y的积| |
`x / y` | x和y |的商| `x / y` | x和y |的商|
`x // y` | x和y |的平均商1| `x // y` | x和y |的平均商1|
`x % y` |剩余的x / y | 2 `x % y` |x除y的余数 | 2
`-x` | x否定| | `-x` | x的相反数| |
`+x` | x不变| | `+x` | x本身| |
`abs(x)` | x |的绝对值或大小| \[ `abs()` `abs(x)` | x |的绝对值或| \[ `abs()`
`int(x)` | x转换为整数| 36| [`int()`](https://docs.python.org/3/library/functions.html#int) `int(x)` | x转换为整数| 36| [`int()`](https://docs.python.org/3/library/functions.html#int)
`float(x)` | x转换为浮点| 46| [`float()`](https://docs.python.org/3/library/functions.html#float) `float(x)` | x转换为浮点| 46| [`float()`](https://docs.python.org/3/library/functions.html#float)
`complex(re, im)` |一个带有实部re的复数虚部im。我默认为零。 | 6| [`complex()`](https://docs.python.org/3/library/functions.html#complex) `complex(re, im)` |一个复数实部为re虚部为im。im默认为零。 | 6| [`complex()`](https://docs.python.org/3/library/functions.html#complex)
`c.conjugate()` |复数c的共轭| `c.conjugate()` |复数c的共轭|
`divmod(x, y)` |对x // yxy| 2| [`divmod()`](https://docs.python.org/3/library/functions.html#divmod) `divmod(x, y)` |x // yxy| 2| [`divmod()`](https://docs.python.org/3/library/functions.html#divmod)
`pow(x, y)` | x到幂y | 5| [`pow()`](https://docs.python.org/3/library/functions.html#pow) `pow(x, y)` | x的y次幂 | 5| [`pow()`](https://docs.python.org/3/library/functions.html#pow)
`x ** y` | x到幂y | 5 `x ** y` | x的y次幂 | 5
**笔记:** **笔记:**
1. 也称为整数除法。结果值是整数但结果的类型不一定是int。结果始终舍入为负无穷大 `1//2`为`0` `(-1)//2`为`-1` `1//(-2)`为`-1` `(-1)//(-2)`为`0` 。 1. 也称为整数除法。结果值是整数但结果的类型不一定是int。结果始终舍入为负无穷大 `1//2`为`0` `(-1)//2`为`-1` `1//(-2)`为`-1` `(-1)//(-2)`为`0` 。
2. 不是复杂的数字。而是在适当的情况下使用`abs()`转换为浮点数。 2. 非复数。在适当的情况下使用`abs()`转换为浮点数。
3. 从浮点到整数的转换可以像C中那样舍入或截断;请参阅函数[`math.floor()`](https://docs.python.org/3/library/math.html#math.floor)和[`math.ceil()`](https://docs.python.org/3/library/math.html#math.ceil)以获得明确定义的转换。 3. 从浮点到整数的转换可以像C中那样舍入或截断;请参阅函数[`math.floor()`](https://docs.python.org/3/library/math.html#math.floor)和[`math.ceil()`](https://docs.python.org/3/library/math.html#math.ceil)以获得明确定义的转换。
4. `float`也接受字符串`“nan”`和`“inf”` ,带有可选前缀`“+”`或`“-”`表示非数字NaN和正或负无穷大。 4. `float`也接受字符串`“nan”`和`“inf”` ,带有可选前缀`“+”`或`“-”`表示非数字NaN和正或负无穷大。
5. Python将`pow(0, 0)`和`0 ** 0`为`1` ,这在编程语言中很常见。 5. Python将`pow(0, 0)`和`0 ** 0`设置为`1` ,这在编程语言中很常见。
6. 接受的数字文字包括数字0到9或任何Unicode等效项具有`Nd`属性的代码点)。 6. 接受的数字文字包括数字0到9或任何Unicode等效项具有`Nd`属性的代码点)。
> 有关具有`Nd`属性的代码点的完整列表,请参阅[Unicode派生数字类型](http://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedNumericType.txt) 。 > 有关具有`Nd`属性的代码点的完整列表,请参阅[Unicode派生数字类型](http://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedNumericType.txt) 。