/ 与 // 的区别
>>> 1 / 2
0.5
>>> 1 // 2
0
向下取整
>>> import math
>>> int(1/2)
0
>>> math.floor(1/2)
0
向上取整
>>> math.ceil(1/2)
1
分别取出整数与小数点
>>> math.modf(4.26)
(0.2599999999999998, 4.0)
四舍五入
>>> round(3.7)
4
>>> round(3.45)
3
round()函数是一个内置函数,并且他还有保留几位小数的功能
>>> round(4.259,2)
4.26
或者使用format保留小数点后几位
>>> '%.1f'%(4.56)
'4.6'
>>> format(4.56,'.1f')
'4.6'