Modulo
Published Oct 8, 2021Updated Oct 8, 2021
Contribute to Docs
In Python, the percent sign (%
) is known as the modulo operator.
A modulo calculation returns the remainder of the division between two numbers.
Example 1
x = 12 % 5print(x) # Output: 2
Because 12 is not evenly divisible by 5, the value of x
is 2.
Example 2
y = 10 % 5print(y) # Output: 0
Because 10 is evenly divisible by 5, the value of y
is 0.
Codebyte Example
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours