首页 > 编程语言 > 详细

python 取整

时间:2020-06-27 17:58:30      阅读:79      评论:0      收藏:0      [点我收藏+]

数据类型

整除

向下取整---//

-1//2,-7//2,-7//3,-7//4,-7//5
>>-1,-4,-3,-2,-2
1//2,7//2,7//3,7//4,7//5,7//6
>>0,3,2,1,1,1

截取整数---int()

int(0.3),int(1.3),int(1.7),int(1.5)
>>0,1,1,1
int(-0.3),int(-4.3)
>>0,-4

向上取整---math.ceil()

math.ceil(0.5),math.ceil(1.1),math.ceil(1.7),math.ceil(0.000011111)
>>1,2,2,1
math.ceil(-0.5),math.ceil(-1.1),math.ceil(-5.7),math.ceil(-0.0000111)
>>0,-1,-5,0

向下取整---math.floor(),等同于//

math.floor(0.5),math.floor(-0.5)
>>0,-1

四舍六入五取偶---round()

round(1.2),round(0.7),round(3.5),round(0.5)
>>1,1,4,0
round(-3.4),round(-3.999),round(-1.5)
>>-3,-4,2

隐式类型转换

isinstance(True,int),type(True),type(1+True),type(1+True+3.00)
>>True, bool, int, float

即使强类型语言,也存在隐式类型转换

python 取整

原文:https://www.cnblogs.com/zoer/p/13198898.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!