The divmod() function is used to get the quotient and remainder of two numbers when they are divided.

It takes two arguments, which are the two numbers to be divided and returns a tuple of two integers, the first integer is the quotient and the other is the remainder of the division.

The divmod() function does not perform the normal division but rather the floor division.

Syntax:

divmod(a, b)

Example:

divmod(5, 2)
//(2, 1)
divmod(9, 3)
//(3, 0)
divmod(-7, 9)
//(-1, 2)

The function is useful in performing some essential operations, for example it can be used to obtain both the quotient (whole number) and the remainder (decimal number) of a floating point value.

Example:

divmod(14.3, 1)
//(14.0, 0.3)
divmod(5.6, 1)
//(5.0, 0.6)
divmod(9.8, 1)
//(9.0, 0.8)