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
python的取模是根据向下取整法的,而c/c++/java是基于向零取整的。
/是精确除法,//是向下取整除法;
print('123 / 10 = ', 123 / 10)
print('123 // 10 = ', 123 // 10)
对于负数还有需要注意的地方:
Python3中,
在c语言中,-53除以10=-5
%是求模,四舍五入取整round, 向零取整int, 向下和向上取整函数math.floor, math.ceil