导语:
本文主要介绍了关于python如何不保留小数的相关知识,包括python定义一个列表,以及python结果不保留小数点这些编程知识,希望对大家有参考作用。
1、int() 向下取整(内置函数)
python学习网,大量的免费
,欢迎在线学习!
n = 3.75
print(int(n))
>>> 3
n = 3.25
print(int(n))
>>> 3
2、round() 四舍五入(内置函数)
n = 3.75
print(round(n))
>>> 4
n = 3.25
print(round(n))
>>> 3
3、floor() 向下取整(math模块函数)
floor的英文释义:地板。顾名思义也是向下取整
import math
n = 3.75
print(math.floor(n))
>>> 3
n = 3.25
print(math.floor(n))
>>> 3
4、ceil()向上取整 (math模块函数)
ceil的英文释义:天花板。
import math
n = 3.75
print(math.ceil(n))
>>> 4
n = 3.25
print(math.ceil(n))
>>> 4
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 谷歌工程师开源:Python 调试神器 Cyberbrain02/06
- ♥ 如何在python中获取列表元素的数量10/20
- ♥ 最全面的12种Python学习方法12/30
- ♥ pyqt5在python中弹出提示框10/03
- ♥ python好找工作吗?01/14
- ♥ Python len()函数详解:获取字符串长度或字节数09/23
内容反馈