Back to Course

Introduction to Python

0% Complete
0/0 Steps
  1. Python: Basics
    14Topics
    |
    15 Quizzes
  2. Python: Control Flow
    12Topics
    |
    12 Quizzes
  3. Python: Errors
    5Topics
    |
    5 Quizzes
Lesson 1, Topic 10
In Progress

Python: Modulo

Yasin Cakal 4 Oct 2021
Lesson Progress
0% Complete

Python includes a modulo operator as a companion to the division operator. Modulo is denoted by percent and returns the remainder of a division calculation. If the number is divisible, the modulo operator returns 0. Here is an example:

# 10 / 3 = 3 + Remainder of 1
print(10 % 3) # Outputs 1

# 10 / 5 = 0 therefore Remainder = 0
print(10 % 5) # Outputs 0

# You can even use Floats
print(10 % 4.5) # Outputs 1.0

In programming, the modulo operator is helpful when we want to perform an action every nth time the code is executed.

%d bloggers like this: