鱼C论坛

 找回密码
 立即注册
查看: 1586|回复: 2

Python divmod() 函数

[复制链接]
发表于 2020-3-14 13:45:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Python divmod() 函数


语法

  1. divmod(x, y)
复制代码


参数

参数描述
x被除数
y除数


返回值

返回一个元组,第一个元素是商,第二个元素是余数。

例子

  1. >>> divmod(10, 3)
  2. (3, 1)
  3. >>> divmod(2.3, 2)
  4. (1.0, 0.2999999999999998)
  5. >>> divmod(5, 3)
  6. (1, 2)
  7. >>> divmod(1, 5)
  8. (0, 1)
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
蒋博文 + 1 + 1 无条件支持楼主!

查看全部评分

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-14 20:46:12 | 显示全部楼层
本帖最后由 永恒的蓝色梦想 于 2020-3-17 08:48 编辑
  1. def divmod(a,b,/):
  2.     try:
  3.         if (res:=a.__divmod__(b)) is not NotImplemented:
  4.             return res

  5.     except:
  6.         pass

  7.     try:
  8.         if (res:=b.__rdivmod__(a)) is not NotImplemented:
  9.             return res

  10.     except:
  11.         raise TypeError(f"unsupported operand type(s) for divmod(): '{type(a).__name__}' and '{type(b).__name__}'")
复制代码

评分

参与人数 1荣誉 +1 收起 理由
一个账号 + 1 鱼C有你更精彩^_^

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-7 22:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表