math模块是一个内置模块,该模块提供了许多对浮点数的数学运算函数
>>> import math
1.ceil() 向上取整操作
>>> res = math.ceil(3.01)
>>> print(res)
4
2.floor() 向下取整操作
>>> res = math.floor(3.9)
>>> print(res)
3
3.pow()计算一个数值的N次方(结果伟浮点数)
>>> res = math.pow(2,3)
>>> print(res)
8.0
4.sqrt() 开平方运算(结果浮点数)
>>> res = math.sqrt(9)
>>> print(res)
3.0
5.fabs() 计算一个数值的绝对值(结果浮点数)
>>> res = math.fabs(-9)
>>> print(res)
9.0
6.modf() 将一个数值拆分为整数和小数两部分组成元组
>>> res = math.modf(-19.8)
>>> print(res)
(-0.8000000000000007, -19.0)
7.copysign() 将参数第二个数值的正负号拷贝给第一个
>>> res = math.copysign(90,-18)
>>> print(res)
-90.0
8.fsum() 将一个容器数据中的数据进行求和和运算
>>> lst = [1,2,3,4]
>>> res = math.fsum(lst)
>>> print(res)
10.0
9.圆周率常数
>>> res = math.pi
>>> print(res)
3.141592653589793