Here we are going to learn all about the Python divmod() function to find the quotient and remainder. When you want to find the quotient and remainder at the same time, Then this python built-in function will be the best function for you.
In our previous Python built-in functions tutorial, we have seen lots of functions along with their examples.
Headings of Contents
Python divmod() function
divmod function Python is a built-in function that returns a tuple containing a quotient and remainder when argument1( dividend ) is divided by argument2 ( divisor ).
Syntax
The syntax of divmod function in python is:-
divmod(dividend, divisor)
Parameters
divmod function in python accepts two parameters.
- dividend:- A number, you want to divide.
- divisor:- A number, you want to divide with.
Return Value
The return value of the divmod function in python is a tuple containing quotient and remainder, that means (quotient, remainder).
Python divmod examples
Let’s see some examples of the divmod() function so that you can understand this function easily.
Example 1:
result = divmod(15, 2)
print(result)
The output will be:- (7, 1)
In the above example, 15 is the dividend and 2 is the divisor and in output 7 is the quotient and 1 is the remainder.
Example 2:
result = divmod(5.2, 2.6)
print(result)
The output will be:- (2.0, 0.0)
In the above example, 5.2 is the dividend and 2.6 is the divisor and in output 2.0 is the quotient, and 0 is the remainder.
Conclusion
In this example, you have learned all about Python divmod function to find the quotient and remainder, when one argument is divided by another one. This python divmod method returns a tuple that contains quotient and remainder.
If this article is helpful for you, please keep visiting for further python built-in functions tutorials.
Other Python built-in functions
For More Information:- Click Here