Function Details: divmod

Description


Returns a tuple of the quotient and remainder when dividing a by b.


Extended Description


The divmod() function takes two numbers as arguments and returns a tuple containing the quotient and the remainder when dividing the first argument by the second. For integers, the result is the same as (a // b, a % b). For floating point numbers, the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that.


Exceptions


  • ZeroDivisionError: If the second argument (b) is zero
  • TypeError: If the arguments are not numbers or are of incompatible types

Read More about divmod from Python Documentation

Function Signature


divmod(a: Number, b: Number) -> Tuple[Number, Number]

Module: builtins

Parameters


a: The dividend (number to be divided). b: The divisor (number to divide by).


Parameter List


  • a: Number
  • b: Number

Return


Returns a tuple (quotient, remainder) of numbers of the same type as the input arguments.


Return Type


Tuple[Number, Number]

Output

Explanation

This example shows how divmod() works with positive and negative integers.