Home >Backend Development >Python Tutorial >What is the usage of divmod function in python?

What is the usage of divmod function in python?

烟雨青岚
烟雨青岚Original
2020-07-03 17:02:3210425browse

In python, you can use the divmod function to combine the results of the divisor and remainder operations and return a tuple containing the quotient and remainder. divmod is a built-in function that does not need to be imported and can be used directly.

What is the usage of divmod function in python?

divmod() function combines the results of the divisor and remainder operations and returns a tuple containing the quotient and remainder

divmod is a built-in function that does not need to be imported and can be used directly

>>> divmod(7,2)
    (3, 1)
    >>> divmod(9,2.5)
    (3.0, 1.5)
#实际应用时可以这么写
carry, remainder = divmod(1010, 10)

Example:

a, b = divmod(5.0, 2.0)
print(a)
print(b)

The result is 2.0 1.0

Recommended tutorial: "python tutorial

The above is the detailed content of What is the usage of divmod function in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn