+ 2
I didn't understand modulo in python. Please explain.
3 ответов
+ 8
Basically what Caleb wrote is right. But it gets tricky when negatives come in:
14 % 5 = 4
14 % -5 = -1
-14 % 5 = 1
-14 % -5 = -4
In Python, unlike some other languages, the modulo result always has the same sign as the divisor (observe the sign of 5 in this example).
+ 1
thanks caleb and kuba for explaining the modulo