Modulo

Christine_Yang's avatar
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 % 5
print(x) # Output: 2

Because 12 is not evenly divisible by 5, the value of x is 2.

Example 2

y = 10 % 5
print(y) # Output: 0

Because 10 is evenly divisible by 5, the value of y is 0.

Codebyte Example

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy