数字类型-int,float,complex¶
所有数字类型(复数除外)都支持下列运算(有关运算优先级,请参阅:运算符优先级):
运算 | 结果: | 完整文档 |
---|---|---|
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 |
x 取反 | |
+x |
x 不变 | |
abs(x) |
x 的绝对值或大小 | abs() |
int(x) |
将 x 转换为整数 | int() |
float(x) |
将 x 转换为浮点数 | float() |
complex(re, im) |
一个带有实部 re 和虚部 im 的复数。im 默认为0。 | complex() |
c.conjugate() |
复数 c 的共轭 | |
divmod(x, y) |
(x // y, x % y) |
divmod() |
pow(x, y) |
x 的 y 次幂 | pow() |
x ** y |
x 的 y 次幂 |
int¶
['as_integer_ratio', 'bit_count', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'is_integer', 'numerator', 'real', 'to_bytes']
float¶
['as_integer_ratio', 'conjugate', 'fromhex', 'hex', 'imag', 'is_integer', 'real']
complex¶
['conjugate', 'imag', 'real']