python中取整数的多种方法

1:向下取整用int()  

a=0.37 

int(a)

-->3

2:四舍五入时用round()

a=0.37

round(a)

-->4

3:向上取整有2中方法

①:向下取整后+1

②:应用math模块  如

import math#调用math模块

a=0.37

math.ceil(a)

-->4

猜你喜欢

转载自www.cnblogs.com/hank-python/p/9213393.html
今日推荐