Python divmod() function
Divide and return both the whole-number result and the remainder.
Syntax
divmod(a, b)
The same as (a // b, a % b) in one call.
Parameters
| a | the number to divide |
| b | the number to divide by |
Return value
a tuple (quotient, remainder)
Example
Code
hours, minutes = divmod(135, 60) print(hours, "h", minutes, "min") print(divmod(17, 5))
Output
2 h 15 min (3, 2)
Related
Learn it step by step in the free lesson Values, Variables & Numbers, with exercises that check your answers.