Python divmod Function with Examples

The divmod function in Python is utilized to obtain both the quotient and the remainder from the division of two numbers. It accepts two numeric parameters and yields a tuple containing the results. Both parameters are mandatory and must be numeric. The syntax for this function is outlined as follows.

Python divmod Function Syntax

It has the following syntax:

Example

divmod (number1, number2)

Parameters

  • number1 : A numeric value, it is required.
  • number2 : A numeric value, it is required.
  • Return

It returns a tuple.

Different Examples for Python divmod Function

Let’s explore a few instances of the divmod function to gain a better understanding of how it operates.

Python divmod Function Example 1

Here’s a straightforward illustration of how to utilize the divmod function.

Example

# Python divmod() function example

# Calling function

result = divmod(10,2)

# Displaying result

print(result)

Output:

Output

(5, 0)

Python divmod Function Example 2

Additionally, it permits the inclusion of floating-point values as parameters. Refer to the example provided below.

Example

# Python divmod() function example

# Calling function

result = divmod(5.5,2.5)

# Displaying result

print(result)

Output:

Output

(2.0, 0.5)

Python divmod Function Example 3

In this instance, we are providing the initial argument as an integer and the subsequent one as a floating-point value.

Example

# Python divmod() function example

# Calling function

result = divmod(5.5,2)

# Displaying result

print(result)

Output:

Output

(2.0, 1.5)

Input Required

This code uses input(). Please provide values below: