On this page
divmod
Prev: dir | Up: __builtins__ | Next: enumerate
Rel: abs, max, min, pow, round
Ref: docs.python.org — divmod
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import divmod
Overview & Signature
divmod(x, y, /)
Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
Usage
mins, secs = divmod(135, 60)
assert (mins, secs) == (2, 15)
Gotchas
- Computes
(a // b, a % b)in one operation: Ideal for base conversion, pagination, and time splitting.
REPL Inspect
help(divmod)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/abs
- tuts/python3/__builtins__/dir
- tuts/python3/__builtins__/enumerate
- tuts/python3/__builtins__/max
- tuts/python3/__builtins__/min
- tuts/python3/__builtins__/pow
- tuts/python3/__builtins__/round
- tuts/python3/__builtins__/sum
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/abs Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/dir Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/enumerate Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/max Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/min Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/pow Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/round Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/sum links to this page; shared tags: #builtins