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()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer