02Python常用模块_01math
1. 取整:
>>> import math >>> math.ceil(2.3) #向上取整 3 >>> math.floor(2.7) #向下取整 2 >>> round(2.3) #四舍五入 2
>>> round(2.12345, 3)
2.123
2. 三角函数:
math.cos(x) math.sin(x) math.tan(x) #返回值是弧度数 math.acos(x) math.asin(x) math.atan(x) math.degrees(x) #弧度到角度 math.radians(x) #角度到弧度
3. 对数&指数:
math.exp(3) #e^x math.pow(x, y) #x^y '''In particular, pow(1.0, x) and pow(x, 0.0) always return 1.0, even when x is a zero or a NaN. ''' math.sqrt(x) #x的2次方根 math.log(2, 4) #log4(2) math.log10(3) #等价于math.log(3, 10)
4. 常数:
math.pi #π math.e #e math.inf #+∞, equivalent to float('inf')