Python divmod() function
Understand the difference between integers and floats in Python and how they define the value types stored in variables at rrtutors.com Check it out!
If you would like to write a small mathematical Python program that divides two integers, verifies divisibility, or checks whether a number is prime or not, and returns the quotient and remainder, you'll need to implement the divmod() function. The divmod() method is a standard Python library function that takes two integers or variables as input and returns a tuple containing the remainder and quotient of their division.
Syntax
divmod(num1, num2) |
Where, num1 and num2 : num2 divides num1
Num1 and num2 can either be integers or floats
Example
In this example, we will test the divisibility of two integers and two floats.
# integers print("7 divide by 3:",divmod(7,3)) print("1000 divide by 10:",divmod(1000,10)) # Floats print("11.5 divide by 3 give:",divmod(11.5,3)) print("19.78 divide by 5.2 give:",divmod(19.78,5.2)) |
Output
![]() |