数学模块_math

ceil

进一, 向上取整

print(math.ceil(5.01))    # 6

floor

向下取整

print(math.floor(5.1))    # 5

pow(x, y)

x的y次方

print(math.pow(2, 3))     # 8.0

sqrt(x)

x的开平方(结果为浮点数)

print(math.sqrt(9))          # 3.0

fabs(x)

计算绝对值

print(math.fabs(-2))      # 2.0

modf

将一个数字差分成整数部分和小数部分, 组成元祖

print(math.modf(15.6))    # (0.5999999999999996, 15.0)

copysign(x, y)

将y的符号给x, 返回浮点类型

print(math.copysign(-1, -2))      # -1.0
print(math.copysign(1, 2))       # 1.0
print(math.copysign(1, -2))          # -1.0

圆周率

print(math.pi)                # 3.141592653589793

猜你喜欢

转载自www.cnblogs.com/caihuajiaoshou/p/10639561.html