Pythonround()函数平局和返回类型
示例
round()
在Python2中,使用round()相等接近两个整数的数字将返回距离0最远的数字。例如:
round(1.5) # 出:2.0 round(0.5) # 出:1.0 round(-0.5) # 出:-1.0 round(-1.5) # 出:-2.0
然而,在Python3中,round()将返回偶数(即银行的四舍五入)。例如:
round(1.5) # 出:2 round(0.5) # 出:0 round(-0.5) # 出:0 round(-1.5) # 出:-2