# Python divmod()

The `divmod()` in Python is a built-in function that takes two numbers as input parameters and returns a pair of numbers (a tuple) consisting of their quotient and remainder.

## divmod() Syntax

The syntax of `divmod()` is:

`divmod(dividend, divisor)`

## divmod() Parameters

divmod() takes two parameters as input

• dividend – The number you want to divide. A non-complex number (numerator)
• divisor – The number you want to divide with. A non-complex number (denominator)

## divmod() Return Value

• `divmod()` returns a pair of numbers (a tuple) consisting of quotient and remainder.

If `x` and `y` are integers, the return value from `divmod()` is `(x / y, x % y)`

If `x` or `y` is a float, the result is`(q, x % y)`where `q `is the whole part of the quotient.

## Example: How divmod() works in Python?

``````
# Python3 code to demonstrate divmod()

# divmod() on integers
print('divmod(4, 2) = ', divmod(4, 2))
print('divmod(5, 3) = ', divmod(5, 3))
print('divmod(6, 6) = ', divmod(6, 6))

# divmod() with Floats
print('divmod(4.0, 2) = ', divmod(4.0, 2))
print('divmod(5.5, 3.3) = ', divmod(5.5, 3.3))
print('divmod(6.5, 6.5) = ', divmod(6.5, 6.5))``````

Output

``````divmod(4, 2) =  (2, 0)
divmod(5, 3) =  (1, 2)
divmod(6, 6) =  (1, 0)

divmod(4.0, 2) =  (2.0, 0.0)
divmod(5.5, 3.3) =  (1.0, 2.2)
divmod(6.5, 6.5) =  (1.0, 0.0)``````

## Errors And Exceptions

1. If either of the arguments (say x and y) is a float, the result is `(q, x % y)`. Here, q is the whole part of the quotient.
2. If the second argument is 0, it returns Zero Division Error
3. If the first argument is 0, it returns (0, 0)

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

##### You May Also Like ## ‘python’ is not recognized as an internal or external command, operable program or batch file.

The ‘python’ is not recognized as an internal or external command, operable program or batch file. error is encountered in the command prompt of Windows after you install Python on the windows… ## AttributeError: Can only use .str accessor with string values

The AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas occurs if you try to replace the values of string column, but in reality,… ## [Solved] NameError: name ‘np’ is not defined

Table of Contents Hide Solution NameError: name ‘np’ is not defined Method 1 – Importing NumPy with Alias as npMethod 2 – Importing all the functions from NumPyMethod 3 –… ## Python Split list into chunks

Table of Contents Hide Python Split list into chunksMethod 1: Using a For-LoopMethod 2: Using the List Comprehension MethodMethod 3: Using the itertools MethodMethod 4: Using the NumPy MethodMethod 5:… ## Python String encode()

Table of Contents Hide SyntaxParameterReturn ValueExample 1- Encode the string to Utf-8 EncodingExample 2- UnicodeEncodeError while encoding stringExample 3- Handling Encoding errors with error parameters Python String encode() method is… ## Python String index()

Table of Contents Hide SyntaxParametersReturn ValueDifference between index() method and find() methodExample 1: Find the index of a string in PythonExample 2: index() method if the stringExample 3: index() method…