divmod()
divmod(x,y) pair of numbers as tuple consisting of quotient and remainder
x : Non complex input number ( numerator or divident )
y : Non complex input number ( denominator or divisor).
Returns tuple with quotient and remainder.
a=29
b=5
my_tuple=divmod(a,b)
print(my_tuple) # (5,4)
The first element of the output is same as output of Floor division and second element is same as output of Modulus .
print(a//b) # 5
print(a%b) # 4
Using float
input numbers are float .
a=53.67
b=7.2
print(divmod(a,b))
Output
(7.0, 3.2700000000000005)
The output is always tuple type.
a=54.6
b=4
print(divmod(a,b))
print(type(divmod(a,b)))
Here is the data type of the element of the output tuple
a=29
b=5
my_tuple=divmod(a,b)
print(my_tuple) # (5,4)
print(type(my_tuple[1])) # <class 'int'>
« All Built in Functions in Python
bin() int()
float()
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com
Python programming Basics ⇩