What is the usage of divmod function in python?

烟雨青岚
Release: 2020-07-03 17:02:32
Original
10384 people have browsed it

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)
Copy after login
#实际应用时可以这么写
carry, remainder = divmod(1010, 10)
Copy after login

Example:

a, b = divmod(5.0, 2.0)
print(a)
print(b)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template