In Python, the percent sign (
%) is known as the modulo operator.
A modulo calculation returns the remainder of the division between two numbers.
x = 12 % 5print(x) # Output: 2
Because 12 is not evenly divisible by 5, the value of
x is 2.
y = 10 % 5print(y) # Output: 0
Because 10 is evenly divisible by 5, the value of
y is 0.
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn Python on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification