python内置函数 divmod()

 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 )

猜你喜欢

转载自blog.csdn.net/weixin_41896508/article/details/80948966