Python divmod() FunctionPython Functions


The divmod() function returns a pair of numbers containing the quotient and the remainder when argument1 (divident) is divided by argument2 (divisor).

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print(divmod(8, 2))
print(divmod(8, 1))
print(divmod(8, 4))
print(divmod(8, 8))

Output:

(4, 0)
(8, 0)
(2, 0)
(1, 0)

Syntax

divmod(divident, divisor)

Parameters

Name Description
divident A Number
divisor A Number

Return Value

It returns a tuple.

© 2021 Programtips.org, all rights reserved. Privacy Policy | Contact Us