Next / Previous / Contents / Shipman's homepage

20.11. divmod(): Quotient and remainder

divmod(x, y)

Sometimes you want both the quotient and remainder when dividing x by y. This function returns a tuple (q, r), where q is the quotient and r is the remainder.

If either x or y is a float, the returned value q is the whole part of the quotient, and the returned r is computed as x-(r*d).


>>> divmod(13, 5)
(2, 3)
>>> divmod(1.6, 0.5)
(3.0, 0.10000000000000009)