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.
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!