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^xmath.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 #emath.inf #+∞, equivalent to float('inf')