数值运算

abs()#返回去绝对值,如果是复数就返回math.sqrt(num.real2+num.imag2)

>>> abs(-1)
1

>>> abs(1.2-2.1j)
2.4186773244895647

coerce()#3.3.5已经不存在

dimod()#返回求余和求除的值

>>> divmod(10,3)
(3, 1)

>>> divmod(2+1j,1+0.5j)#版本高的情况下不在对复数进行操作 我的是3.3.5没用使用常见的2.7
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
divmod(2+1j,1+0.5j)
TypeError: can't take floor or mod of complex number.

pow()#指数操作

>>> pow(2,3)
8

>>> pow(1+1j,3)
(-2+2j)

round()#四舍五入进0求值

>>> round(3.55642,2)
3.56

>>> round(-5.23645,2)
-5.24

>>> round(-0.115,1)
-0.1

原文地址:https://www.cnblogs.com/timp/p/3665165.html