#python数学类运算完美总结
>>> abs(-1) #表示绝对值
1
>>> divmod(11,5) #(a//b,a%b)
(2, 1)
>>> pow(5,2) #表示5**2=25
25
>>> pow(5,2,20) #表示(5**2)%20=5 最后为模运算
5
>>> round(4.99) #四舍五入取整数,不保留小数
5
>>> round(4.589,2) #保留2位小数=4.59
4.59
>>> max(1,2,5,10) #找出最大值
10
>>> min(10000,20000,4.1e2) #找出最小值
410.0
>>> 4.1e2 #表示科学计数法4.1*(10**2)
410.0
>>> int(10.99) #将浮点数转为整数,向下取整
10
>>> float((10+5j).real) #转化为浮点数
10.0
>>> complex(2,5) #生成复数
(2+5j)
>>> import math
>>> math.pi #π
3.141592653589793
>>> math.e #自然数e
2.718281828459045
>>> math.inf #正无穷大,负无穷大-math.inf
inf
>>> math.nan #not a number 非浮点数标记
nan
>>> math.fabs(-1) #返回x的绝对值
1.0
>>> math.fmod(11,5) #返回模运算11%5=1 类似于divmod()后半段运算
1.0
>>> math.fsum(1,2,3,4) #浮点数精确求和
Traceback (most recent call last):
File "", line 1, in
math.fsum(1,2,3,4) #浮点数精确求和
TypeError: fsum() takes exactly one argument (4 given)
>>> math.fsum([1,2,3,4]) #浮点数精确求和
10.0
>>> math.ceil(10.59) #向上取整=11
11
>>> math.floor(10.59) #向下取整,类似与int=10
10