Python中的取整运算
1.int()向下取整
1 n = 3.75
2 print(int(n))
>>>3
2.round() 四舍五入取整
1 n = 3.75
2 print(round(n))
>>> 4
3.floor() 向下取整 math模块函数
1 import math
2 n = 3.75
3 print(math.floor(n))
>>> 3
4.ceil()向上取整 math模块函数
1 n = 3.25
2 print(math.ceil(n))
>>> 4
5.modf() 分别取整数部分和小数部分 math模块函数
1 import math
2 n = 3.75
3 print(math.modf(n))
>>> (0.75, 3.0)