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
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)))
Output
(13.0, 2.6000000000000014)
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'>
print(divmod(-20, 3)) # Output: (-7, 1)
for i in range(1, 6):
q, r = divmod(20, i)
print(f"Dividing 20 by {i}: Quotient = {q}, Remainder = {r}")
Output
Dividing 20 by 1: Quotient = 20, Remainder = 0
Dividing 20 by 2: Quotient = 10, Remainder = 0
Dividing 20 by 3: Quotient = 6, Remainder = 2
Dividing 20 by 4: Quotient = 5, Remainder = 0
Dividing 20 by 5: Quotient = 4, Remainder = 0
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.