Home »
Python »
Python Reference »
Python Built-in Functions
Python divmod() Function: Use, Syntax, and Examples
Python divmod() function: In this tutorial, we will learn about the divmod() function in Python with its use, syntax, parameters, returns type, and examples.
By IncludeHelp Last updated : June 23, 2023
Python divmod() function
The divmod() function is a library function in Python, it is used to get the quotient and remainder of given values (dividend and divisor), it accepts two arguments: dividend and divisor, and returns a tuple that contains quotient and remainder.
Syntax
The following is the syntax of divmod() function:
divmod(dividend, divisor)
Parameter(s):
The following are the parameter(s):
- dividend – a number to be divided.
- divisor – a number to be divided with.
Return Value
The return type of divmod() function is <class 'tuple'>, it returns a tuple containing quotient and remainder.
Python divmod() Function: Example 1
# Example of Python divmod() Function
x = 10
y = 3
print(divmod(x, y))
x = 21
y = 7
print(divmod(x, y))
Output
(3, 1)
(3, 0)
Python divmod() Function: Example 2
Python code to find quotient and remainder of two numbers.
# python code to demonstrate example of
# divmod() number
a = 10 #dividend
b = 3 #divisor
print("return type of divmod() function: ", type(divmod(a,b)))
# finding quotient and remainder
result = divmod(a,b)
print("result = ", result)
# float values
a = 10.23 #dividend
b = 3.12 #divisor
# finding quotient and remainder
result = divmod(a,b)
print("result = ", result)
Output
return type of divmod() function: <class 'tuple'>
result = (3, 1)
result = (3.0, 0.8700000000000001)