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:
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.
# Python divmod() function example
# Calling function
result = divmod(10,2)
# Displaying result
print(result)
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.
# Python divmod() function example
# Calling function
result = divmod(5.5,2.5)
# Displaying result
print(result)
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.
# Python divmod() function example
# Calling function
result = divmod(5.5,2)
# Displaying result
print(result)
Output:
(2.0, 1.5)