Python3 divmod() Function
The Python divmod() function takes two numeric (non-complex) arguments and returns a tuple containing the quotient and the remainder (a // b, a % b).
This function does not support complex numbers in Python 3.x versions.
Function Syntax
divmod(a, b)
Parameter Descriptions:
- a: A number, non-complex.
- b: A number, non-complex.
If both parameters a and b are integers, the function returns the result equivalent to (a // b, a % b).
If one of the parameters is a floating-point number, the function returns the result equivalent to (q, a % b), where q is usually math.floor(a / b), but might be 1 less, although q * b + a % b will be very close to a.
If the remainder (a % b) is not zero, the sign of the remainder is the same as that of parameter b. If b is positive, the remainder is positive; if b is negative, the remainder is negative, and 0 <= abs(a % b) < abs(b).
Examples
>>> divmod(7, 2)
(3, 1)
>>> divmod(8, 2)
(4, 0)
>>> divmod(8, -2)
(-4, 0)
>>> divmod(3, 1.3)
(2.0, 0.3999999999999999)