Python divmod()

divmod() overview

The divmod() method takes two numbers as argument and returns the quotient and remainder as tuple

divmod() integers

# divmod() function example with integers print(divmod(5, 5)) print(divmod(10, 5)) print(divmod(5, 10)) (1, 0) (2, 0) (0, 5)

divmod() floats

# divmod() function example with integers print(divmod(5.5, 5.5)) print(divmod(10.2, 5.2)) print(divmod(1.0, 10.11)) (1.0, 0.0) (1.0, 4.999999999999999) (0.0, 1.0)

divmod() syntax

The syntax of divmod() is as follows: divmod(x, y)

divmod() arguments

The built-in Python function divmod() takes exactly two arguments, both are required. The arguments have to be non-complex numbers. If less or more than two arguments are given, a TypeError is returned. The first argument is the numerator and the second argument is the denominator.

divmod() return values

Python's divmod() method returns a tuple consisting of quotient and remainder. The first number in the tuple is the quotient and the second number is the remainder.



Click to jump to section