博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
02Python常用模块_01math
阅读量:4660 次
发布时间:2019-06-09

本文共 642 字,大约阅读时间需要 2 分钟。

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')

 

转载于:https://www.cnblogs.com/zhangyide/p/8268248.html

你可能感兴趣的文章