divmod() in python

The divmod() built-in function combines division and modulus operations into a single function call that returns the pair (quotient, remainder) as a tuple. The values returned are the same as those given for the standalone division and modulus operators for integer types. For floats, the quotient returned is math.floor( num1/num2 ) and for complex numbers, the quotient is math.floor(( num1/num2 ).real).

>>> divmod(10,3)
(3, 1)
>>> divmod(3,10)
(0, 3)
>>> divmod(10,2.5)
(4.0, 0.0)
>>> divmod(2.5,10)
(0.0, 2.5)
>>> divmod(2.1j,0.5-1j)
((-2+0j), (1+0.10000000000000009j))

You may also like...