The Intracices of the Python Modulo Operator

Programming
Python
Modulating the Modulator
Published

December 2, 2025

Divisor larger than dividend:

Divisor smaller than dividend:

Negative divisor (in Python, the remainder must always be positive):

Handy template expression to use: divisor = ? * dividend + remainder, where ? is the number of times the dividend fits into the divisor. - 158%100: 158 = ? * 100 + remainder - -18%100: -18 = ? * 100 + remainder - In Python, the remainder must always be positive. Thus, ? in this case is -1.

How to read modulo expressions in Chinese: - 158%100: 158模100 或 158对100取模

Back to top