TUTORIAL编程语言与算法FETCHED
Python divmod() 函数
Python divmod() 函数 Python 内置函数 python divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。 在 python 2.3 版本之前不允许处理复数。 函数语法 divmod(a, b) 参数说明: a: 数字 b: 数字 实例 [mycode3 type='python'] >>> divm..
更新于 2026/7/16
教程详情页默认 noindex。
Python divmod() 函数
python divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。
在 python 2.3 版本之前不允许处理复数。
函数语法
divmod(a, b)
参数说明:
- a: 数字
- b: 数字
实例
>>>divmod(7, 2)
(3, 1)
>>> divmod(8, 2)
(4, 0)
>>> divmod(1+2j,1+0.5j)
((1+0j), 1.5j)
Python 内置函数