Modulo Operator
Hi all
I found this and could you tell me what I missed
1
result = 10 % 3
print(result) # Output: 1
2
result = 7 % -3
print(result) # Output: -2
as according to the math in second code I'll get the same output as in first one
so 7 -> 3*2 -> 6 and 7- 6 = 1 and not -2
3 comments · 84% upvoted · other discussions
https://stackoverflow.com/questions/5584586/find-the-division-remainder-of-a-number
That
%operator returns the true modulus. This is why some languages have amodand aremoperator.Have a look at
math.remainder()Outputs..