Editor settings

General settings

Save settings

Learn to program with Python

Finding a remainder from division #

In Python, the modulo operator % returns the remainder when one number is divided by another. For example, a % b returns the remainder when a is divided by b. The modulo operator is often used in programming to determine if a number is even or odd, or to wrap a value around a certain range.

Here are some examples of using the modulo operator in Python:

# 7 % 2 evaluates to 1, because 7 divided by 2 has a remainder of 1.
print(7 % 2) # output: 1

# 10 % 5 evaluates to 0, because 10 divided by 5 has no remainder.
print(10 % 5) # output: 0

Exercise #

  • Set the variable x to be the remainder when 15 is divided by 2
  • Must use the % sign
Output will be displayed here