There's the % sign. It's not just for the remainder, it is the modulo operation.
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
3 weeks ago - This module provides access to common mathematical functions and constants, including those defined by the C standard. These functions cannot be used with complex numbers; use the functions of the ...
Modulo operator
A modulo is a mathematical operator used in modular arithmetic You can think about modular arithmetic like how time on an analog clock works. In a 12 hr clock, if it’s currently 10, in 3 hours it will be 1, not 13. This is expressed as 10 + 3 mod 12. The modulo operator returns that result. num = (10 + 3) % 12 print(num) Would output 1. People like thinking about this as the remainder, but that’s not really accurate. For example: -1 % 4 would actually equal 3. If you think about a 4-hr clock and go back 1 hour, you end up at 3. More on reddit.com
Python, unlike C, has the mod operator always return a positive number
There are technically 5 different versions of this operation, though only 2 (possibly 3) are in common use. Common Lisp seems to implement all of them except, somewhat oddly, the euclidean version (the "actual modulo"), its mod function is instead a flooring division · edit: it looks like ... More on news.ycombinator.com
What is the numpy.mod() function in Python?
The numpy.mod() function calculates the modulus of each element in two arrays element-wise, which is useful when working with large datasets.
upgrad.com
upgrad.com › home › tutorials › software & tech › modulus in python
Modulus in Python | Definition, Syntax & Use Cases
What is the purpose of math.fmod() in Python?
The math.fmod() function provides more precision than the % operator when calculating the modulus for floating-point numbers, especially with very small or large decimal numbers.
upgrad.com
upgrad.com › home › tutorials › software & tech › modulus in python
Modulus in Python | Definition, Syntax & Use Cases
Can I calculate modulus for multiple numbers in Python?
Yes, you can calculate the modulus of multiple numbers using a function. For example, a custom function can return the modulus of several numbers sequentially.
upgrad.com
upgrad.com › home › tutorials › software & tech › modulus in python
Modulus in Python | Definition, Syntax & Use Cases
Videos
01:44
Python Modulo: Using the % Operator (Overview) (Video) – Real Python
08:13
Performing Modulo Operation in Python - YouTube
04:25
How To Use Modulo Operations In Python - YouTube
20:14
Mathematics with Python! Modular Arithmetic - YouTube
10:36
Using the Python Modulo % Operator - YouTube
04:53
math basics - modulus (Python) - YouTube
Real Python
realpython.com › python-modulo-operator
Python Modulo Operator (%): How to Use Mod in Python – Real Python
April 1, 2023 - Just like with the division operator (/), Python will return a ZeroDivisionError if you try to use the modulo operator with a divisor of 0: ... Next, you’ll take a look at using the modulo operator with a float. Similar to int, the modulo operator used with a float will return the remainder of division, but as a float value: ... An alternative to using a float with the modulo operator is to use math.fmod() to perform modulo operations on float values:
Reddit
reddit.com › r/learnpython › modulo operator
r/learnpython on Reddit: Modulo operator
November 22, 2023 -
Hey guys, I just started learning python and im learning about "modulo operator" in the codeacademy free course and my english isn't perfect and im not good at math at all so i'm lost, and also idk if i should be seeing this if literally i dont know anything about coding, just starting the basics. ty
Top answer 1 of 5
19
A modulo is a mathematical operator used in modular arithmetic You can think about modular arithmetic like how time on an analog clock works. In a 12 hr clock, if it’s currently 10, in 3 hours it will be 1, not 13. This is expressed as 10 + 3 mod 12. The modulo operator returns that result. num = (10 + 3) % 12 print(num) Would output 1. People like thinking about this as the remainder, but that’s not really accurate. For example: -1 % 4 would actually equal 3. If you think about a 4-hr clock and go back 1 hour, you end up at 3.
2 of 5
4
When I was at school we called it remainder. What is 11 divided by 3? The answer is 3 remainder 2. The modulo operator gives you the remainder part of the division, ignoring the main answer. So 11 % 3 gives 2 And hence N % M always returns an answer between 0 and (M - 1).
W3Schools
w3schools.com › python › module_math.asp
Python math Module
Python has a built-in module that you can use for mathematical tasks.
Readthedocs
mod.readthedocs.io
mod – modular arithmetic in Python — mod 0.3.0 documentation
from mod import Mod # Funny math here x = Mod(5, 7) # x ≡ 5 (mod 7) (x + 2) == 0 # True: 5 + 2 ≡ 7 ≡ 0 (mod 7) (x + 7) == x # True: 5 + 7 ≡ 12 ≡ 5 (mod 7) (x**3) == (x + 1) # True: 5³ ≡ 125 ≡ 6 (mod 7) (1 // x) == 3 # True: 5 × 3 ≡ 15 ≡ 1 (mod 7) ⇒ 5⁻¹ ≡ 3 (mod 7)
GitHub
github.com › yoeo › mod
GitHub - yoeo/mod: Modular arithmetic in Python :100:
The purpose of this package is to simplify the use of modular arithmetic in Python3. This package provides Mod integers that compute arithmetic operations like + - * // ** with a modulus: from mod import Mod # Funny math here x = Mod(5, 7) # x ≡ 5 (mod 7) (x + 2) == 0 # True: 5 + 2 ≡ 7 ≡ 0 (mod 7) (x + 7) == x # True: 5 + 7 ≡ 12 ≡ 5 (mod 7) (x**3) == (x + 1) # True: 5³ ≡ 125 ≡ 6 (mod 7) (1 // x) == 3 # True: 5 × 3 ≡ 15 ≡ 1 (mod 7) ⇒ 5⁻¹ ≡ 3 (mod 7)
Starred by 13 users
Forked by 4 users
Languages Python 100.0% | Python 100.0%
DataCamp
datacamp.com › tutorial › modulo-operator-python
Modulo Operator in Python: Understanding Key Concepts | DataCamp
March 12, 2025 - The modulo operator (%) in Python calculates the remainder of a division operation. It follows a consistent mathematical formula:
Upgrad
upgrad.com › home › tutorials › software & tech › modulus in python
Modulus in Python | Definition, Syntax & Use Cases
June 2, 2025 - For example, -17 % 5 returns 3. The math.fmod() function provides more precision than the % operator when calculating the modulus for floating-point numbers, especially with very small or large decimal numbers.
AskPython
askpython.com › home › python modulo – % operator, math.fmod() examples
Python Modulo - % Operator, math.fmod() Examples - AskPython
February 16, 2023 - Python modulo operator always return the remainder having the same sign as the divisor. This can lead to some confusion with the output. ... The behavior of % operator with negative numbers is different from the platform C library. If you want the modulo operation to behave like C programming, you should use math module fmod() function.
Wikipedia
en.wikipedia.org › wiki › Modulo
Modulo - Wikipedia
2 weeks ago - The range of values for an integer modulo operation of n is 0 to n − 1. a mod 1 is always 0. When exactly one of a or n is negative, the basic definition breaks down, and programming languages differ in how these values are defined. In mathematics, the result of the modulo operation is an ...
Stanford CS
cs.stanford.edu › people › nick › py › python-math.html
Python Math
Language aside: other languages ... float division and // for int division, and this seems easier to understand. The "modulo" or "mod" operator % is essentially the remainder after int-division....
Python
docs.python.org › 3 › library › operator.html
operator — Standard operators as functions
The operator module exports a set of efficient functions corresponding to the intrinsic operators of Python. For example, operator.add(x, y) is equivalent to the expression x+y. Many function names are those used for special methods, without the double underscores. For backward compatibility, many of these have a variant with the double underscores kept. The variants without the double underscores are preferred for clarity. The functions fall into categories that perform object comparisons, logical operations, mathematical operations and sequence operations.
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.mod.html
numpy.mod — NumPy v2.1 Manual
Equivalent of Python // operator. ... Simultaneous floor division and remainder. ... Equivalent of the MATLAB rem function. ... Returns 0 when x2 is 0 and both x1 and x2 are (arrays of) integers. mod is an alias of remainder.
Hacker News
news.ycombinator.com › item
Python, unlike C, has the mod operator always return a positive number | Hacker News
January 3, 2022 - There are technically 5 different versions of this operation, though only 2 (possibly 3) are in common use. Common Lisp seems to implement all of them except, somewhat oddly, the euclidean version (the "actual modulo"), its mod function is instead a flooring division · edit: it looks like ...
Codecademy
codecademy.com › docs › python › modulo
Python | Modulo | Codecademy
April 15, 2025 - The modulo operator (%) in Python calculates the remainder of a division operation between two operands. When one number is divided by another, the modulo operation returns what remains after the division is performed.