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.
Python divmod() function
Python divmod function is the python built-in function that returns a tuple containing quotient and remainder when argument1( dividend ) divided by argument2 ( divisor ).
The syntax of divmod function in python is:-
divmod function in python accepts two parameters.
- dividend:- A number, you want to divide.
- divisor:- A number, you want to divide with.
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 python divmod method so that you can understand this function easily.
result = divmod(15, 2) print(result)
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.
result = divmod(5.2, 2.6) print(result)
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.
In this example, you have learned all about Python divmod function to find the quotient and remainder, when one argument is divide 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