1、向上取整math.ceil()函数

import math

print(math.ceil(1.7))
print(math.ceil(0.3))
print(math.ceil(-1.7))
print(math.ceil(-.3))

运行结果

2
1
-1
0

2、向下取整math.floor()函数

import math

print(math.floor(1.7))
print(math.floor(.3))
print(math.floor(-1.7))
print(math.floor(-0.3))

运行结果

1
0
-2
-1

3、指数运算math.pow()函数

import math

print(math.pow(15, 3))
print(math.pow(2, -1))

输出结果

3375.0
0.5

4、对数运算(默认底数为e,可以使用第二个参数来改变对数的底数)

import math

print(math.log(3))
print(math.log(100, 10))

输出结果

1.0986122886681098
2.0

你也可能喜欢

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注