Python negative number remainder, divisible

Directly upload the code, the explanation is in the comments, if you don’t understand the comments, you must reply

print(11/2)     #5.5
print(11/-2)    #-5.5        
print(11//2)    #5
print(11//-2)   #-6     一正一负,-5 向下取整 = -6
print(11%2)     #1
print(11%-2)    #-1		一正一负,用公式:被除数-除数*商  在本题就是 11-(-2*(11//-2))=11-(-2*(-6))=-1
                       

Guess you like

Origin blog.csdn.net/weixin_43402353/article/details/109155421
Recommended