**New course!**Every coder should learn

**Generative AI!**

+ 2

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

3 Answers

+ 10

The modulo operator divides two numbers and returns the remainder.
Example: 7%6=1

+ 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