ScanSkill

divmod

This divmod() function returns a quotient and remainder after a division of two numbers.

Syntax

divmod(dividend, divisor)

Here,

  • dividend: Required. A number you want to divide.
  • divisor: Required. A number you want to divide with.

Note: With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (a // b, a % b). For floating-point numbers, the result is (q, a % b), where q is math.floor(a/b).

Examples

>>> divmod(10, 3)
(3, 1)
>>> divmod(10.5, 3)
(3.0, 1.5)
>>> divmod(10.5, 3.1)
(3.0, 1.1999999999999997)
>>> divmod(10.5, 3.5)
(3.0, 0.0)