TUTORIALProgrammingFETCHED

Python divmod() 函数

Python divmod() 函数 Python 内置函数 python divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。 在 python 2.3 版本之前不允许处理复数。 函数语法 divmod(a, b) 参数说明: a: 数字 b: 数字 实例 [mycode3 type='python'] >>> divm..

Updated 7/16/2026

Tutorial detail pages default to noindex.

Python divmod() 函数

Python 内置函数 Python 内置函数

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 内置函数 Python 内置函数