divmod
Divide one number by another and get the quotient and remainder in one call.
Python 3.13
divmod(a, b)- a
- The dividend.int | float
- b
- The divisor.int | float
Return value
A tuple (a // b, a % b): two ints for integer arguments, two floats if at least one argument is a float. For example, divmod(7.5, 2) gives (3.0, 1.5).
Examples
Quotient and remainder
Python 3.13
print(divmod(10, 3))(3, 1)
Dividing a negative number
Python 3.13
print(divmod(-7, 2))(-4, 1)
Details
The quotient is rounded down, so divmod(-7, 2) gives (-4, 1). Raises ZeroDivisionError if b is 0.
