Python divmod() Function with Examples

The divmod() built-in python function is used to return a tuple which consists the quotient and the remainder of given two number...

In this tutorial, we will discuss about the divmod() function in python programming language with the help of examples.

Python divmod() function

Python divmod() function

The built-in python function is used to return a tuple which consists the quotient and the remainder of given two numbers.

Syntax 

divmod(x, y)

Parameters of divmod() function in python 

The function in python takes two arguments or parameters i.e.,

- numerator which is a non-complex number.

- denominator which is also a non-complex number.

Return value of Python divmod() function 

The python function is used to return to return a tuple which consists the quotient and the remainder of given two numbers.

Note - The divmod() function will return a value like , if the two numbers are integers. And it will return a value like , is quotient's whole part, if the two numbers are float.

Example 1: Call simple divmod function in Python

# A Python program to illustrate divmod() function

foo = divmod(12,3)  

print(foo)  

Output

(4, 0)

Example 2: Passing float values with divmod() function in Python

# A Python program to illustrate divmod() function with float 

foo = divmod(10.5,5.5)  

print(foo)

Output

(1.0, 5.0)

Example 3: Passing integer and float value with Python divmod() function

# A Python program to illustrate divmod() function in python 

# with integer and float value

foo = divmod(10.5,4)  

print(foo)

Output

(2.0, 2.5)