Python divmod() function
Python divmod() function The divmod() function in Python returns a tuple containing the quotient and the remainder when parameter ‘a’ (divident) is divided by parameter ‘b’ (divisor). Syntax:
divmod(a, b)Parameter a: This parameter represents a number you want to divide i.e., the dividend. b: This parameter represents a number that you want to divide with i.e., the divisor. Return This function returns a pair of numbers consisting of their quotient and remainder. Example 1
# Python Program explaining # divmod() function x = divmod(52, 2) print('divmod() function will return: ',x)Output
divmod() function will return: (26, 0)Example 2
# Python Program explaining # divmod() function print('(15, 14) = ', divmod(5, 4)) print('(140, 16) = ', divmod(10, 16)) # divmod() with int and Floats print('(62.0, 45) = ', divmod(8.0, 3)) print('(33, 29.0) = ', divmod(3, 8.0))Output
(15, 14) = (1, 1) (140, 16) = (0, 10) (62.0, 45) = (2.0, 2.0) (33, 29.0) = (0.0, 3.0)