The divmod function
The divmod
function returns a tuple of the quotient (the number obtained by dividing one number by another) and the remainder of the division. In the first parameter of the method, we specify the number to be divided (the dividend), in the second parameter - the number by which we divide the first (the divisor).
Syntax
divmod(dividend, divisor)
Example
Let's find the quotient and remainder when dividing the number 20
by 5
:
print(divmod(20, 5))
Result of code execution:
(4, 0)
Example
Now let's apply the function divmod
to the number 21
:
print(divmod(21, 5))
Result of code execution:
(4, 1)
Example
Let's find the quotient and remainder when dividing the number -15
by 2
:
print(divmod(-15, 2))
Result of code execution:
(-8, 1)