I didn't understand modulo in python. Please explain. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

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

23rd Mar 2017, 2:12 PM
Sajid Khan
Sajid Khan - avatar
3 Answers
+ 10
The modulo operator divides two numbers and returns the remainder. Example: 7%6=1
23rd Mar 2017, 2:19 PM
Caleb Jore
Caleb Jore - avatar
+ 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