![图片[1]-python中如何使用round函数-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5dba72e8134ad719.gif)
在python3中,round(1.0/2.0)得到的是1,而在python2中,round(1.0/2.0)得到的是0
$python Python2.7.8(default,Jun182015,18:54:19) [GCC4.9.1]onlinux2 Type"help","copyright","credits"or"license"formoreinformation. >>>round(0.5) 1.0
$python3 Python3.4.3(default,Oct142015,20:28:29) [GCC4.8.4]onlinux Type"help","copyright","credits"or"license"formoreinformation. >>>round(0.5) 0
使用的一般语法是round(number,digits)
number,要四舍五入的数,digits是要小数点后保留的位数
如果digits大于0,则四舍五入到指定的小数位。 如果digits等于0,则四舍五入到最接近的整数。 如果digits小于0,则在小数点左侧进行四舍五入。 如果round函数只有参数number,等同于digits等于0。原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容