Built-in Functions and Types

divmod()

Calculate quotient and remainder together. For integers, the pair agrees with floor division and modulo: a = q*b + r, and a nonzero remainder follows the divisor’s sign. Floating-point pairs can differ from exact arithmetic because of rounding. A zero divisor raises ZeroDivisionError; built-in complex numbers do not support the operation.

Formal Syntax & Structure

python syntaxpython
divmod(a, b, /)

Parameters & Attributes

NameTypeDescription
anumberDividend.
bnumberNonzero divisor.

Return Value

tuple

Two elements in order: quotient, remainder; custom numeric protocols can define their own result.

Working Example

Example Snippetpython
minutes = 137hours, remaining = divmod(minutes, 60)print(hours, remaining)print(divmod(-7, 3))
Python Reference