python中divmod
Python divmod()函数 (Python divmod() function)
divmod() function is a library function, it is used to get the quotient and remainder of given values (dividend and divisor), it accepts two arguments 1) dividend and 2) divisor and returns a tuple that contains quotient and remainder.
divmod()函数是一个库函数,用于获取给定值的商和余数 ( 被除数和除数 ),它接受两个参数1) 除数和2) 除数,并返回一个包含商和余数的元组。
Syntax:
句法:
divmod(dividend, divisor)
Parameter(s):
参数:
dividend – a number to be divided.
红利 –要除的数字。
divisor – a number to be divided with.
除数 –要除的数字。
Return value: tuple – it returns a tuple containing quotient and remainder.
返回值: tuple –返回包含商和余数的元组香港vps。
Example:
例:
Input: a = 10 #dividend b = 3 #divisor # finding quotient and remainder result = divmod(a,b) print(“result = “, result) Output: result = (3, 1)
Python code to find quotient and remainder of two numbers
Python代码查找两个数字的商和余数
# python code to demonstrate example of # divmod() numbera = 10 #dividendb = 3 #divisorprint(“return type of divmod() function: “, type(divmod(a,b)))# finding quotient and remainderresult = divmod(a,b)print(“result = “, result)# float valuesa = 10.23 #dividendb = 3.12 #divisor# finding quotient and remainderresult = divmod(a,b)print(“result = “, result)
Output
输出量
return type of divmod() function: <class ‘tuple’>result = (3, 1)result = (3.0, 0.8700000000000001)
翻译自: https://www.includehelp.com/python/divmod-function-with-example.aspx
python中divmod
64075652