python 取模和/除法的注意事项

python的取模是根据向下取整法的,而c/c++/java是基于向零取整的。

python3中:

 /是精确除法,//是向下取整除法;

print('123 / 10 = ', 123 / 10)
print('123 // 10 = ', 123 // 10)

 

对于负数还有需要注意的地方:

Python3中,

在c语言中,-53除以10=-5 

%是求模,四舍五入取整round, 向零取整int, 向下和向上取整函数math.floor, math.ceil

扫描二维码关注公众号,回复: 9534607 查看本文章
发布了83 篇原创文章 · 获赞 14 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_38121168/article/details/103323418