Trusted answers to developer questions

Educative Answers Team

The Python modulo operator, **%**, is used to retrieve the remainder after a division.

The basic syntax of the python modulo used in an equation is as follows:

# Syntax to get a remainder from a division in Python argument1 % argument2 = remainder of (argument1/argument2)

In this example, when we divide the first argument, 6, by the second argument, 2 - the result of the division is 3 with 0 as a remainder.

So in Python, **6 % 2 = 0**

In this example, when we divide the first argument, 9, by the second argument, 7 - the result of the division is $ {1}\frac{2}{7}$ with 2 as a remainder.

So in Python, **9 % 7 = 2**

The only exception you get with a python modulo operator **ā%ā** is when the second argument is 0. This means that the divider operand of the modulo operator cannot be zero.

For example:

argument1 = 8 argument2 = 0 exceptionRemainder = argument1 % argument2 print(exceptionRemainder)

RELATED TAGS

modulo

python

operator

Copyright Ā©2022 Educative, Inc. All rights reserved

RELATED COURSES

View all Courses

Keep Exploring

Related Courses