+ 2

I didn't understand modulo in python. Please explain.

23rd Mar 2017, 2:12 PM
Sajid Khan
Sajid Khan - avatar
2 Answers
+ 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).
23rd Mar 2017, 9:15 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 1
thanks caleb and kuba for explaining the modulo
24th Mar 2017, 7:24 AM
Sajid Khan
Sajid Khan - avatar