Modulo

garanews's avatar
Published Jan 28, 2022Updated Oct 26, 2022
Contribute to Docs

Modulo is a mathematical operation that returns the remainder of a division of two arguments. It is available in every programming language.

  • Start your programming journey with an introduction to the world of code and basic concepts.
    • Includes 5 Courses
    • With Certificate
    • Beginner Friendly.
      4 hours
  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

Syntax

The remainder is what is left over after dividing the first argument, the dividend, by the second, the divisor or modulus:

remainder = dividend % divisor

Most programming languages use the % symbol to represent the modulo operation, though some may use mod or other variations.

Examples

The following is an example of the modulo operator in Python:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn General on Codecademy

  • Start your programming journey with an introduction to the world of code and basic concepts.
    • Includes 5 Courses
    • With Certificate
    • Beginner Friendly.
      4 hours
  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours