英文文档:

divmod(a, b)

Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using integer division. With mixed operand types, the rules for binary arithmetic operators apply. For integers, the result is the same as (a // b, a % b). For floating point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that. In any case q * b + a % b is very close to a, if a % b is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b).

说明:

  1. 接受两个数值(非复数),返回两个数值的相除得到的商,和余数组成的元组。

  2. 如果参数都是整数,执行的是地板除,相当于 (a//b,a%b)。

>>> divmod(5,2)
(2, 1)
>>> 5//2
2
>>> 5%2
1

  3. 如果参数时浮点数,相当于( math.floor(a/b),a%b)。

>> divmod(5.5,2)
(2.0, 1.5)
>>> math.floor(5.5/2)
2
>>> 5.5/2
2.75
>>> math.floor(5.5/2.0)
2
>>> 5.5%2
1.5

最新文章

  1. 【工匠大道】Git的使用总结
  2. ios上position:fixed失效问题
  3. 基于@Aspect的AOP配置
  4. Eclipse下Tomcat插件的安装
  5. Dictionary序列化和反序列化
  6. eclipse 切换svn账号
  7. Spring强制使用CGLIB代理事务
  8. MVC使用Exception过滤器自定义处理Action的的异常
  9. Java订单号(时间加流水号)
  10. web.xml的配置问题
  11. 离PACKET_INp获取信息acket data
  12. 【Linux】查看系统位数
  13. iis / asp.net 使用 .config 和 .xml 文件的区别
  14. aliyun添加数据盘parted方式分区格式化和lvm挂载及数据盘的扩容
  15. 如何使用PowerDesigner设计数据库关系模式
  16. 奇淫怪巧之在Delphi中调用不申明函数
  17. 1.2socket服务器使用多线程
  18. openstack-on-centos7之环境准备
  19. activiti 用户手册中 10分钟 小例子 简单代码搭建 及 其中的 各种坑
  20. 编程哲学之C#篇:01——创世纪

热门文章

  1. 使用Windows Service Wrapper快速创建一个Windows Service 如nginx
  2. kafka 客户端 producer 配置参数
  3. Spring 1 控制反转、依赖注入
  4. SpringBoot主程序注解@SpringBootApplication简单分析
  5. myBase Desktop 6.5.1 无限期试用
  6. C语言第零次作业
  7. HTTP协议头部与Keep-Alive模式详解(转)
  8. Influxdb+Grafana+Telegraf及docker中运行
  9. [jzoj]3468.【NOIP2013模拟联考7】OSU!(osu)
  10. MyBatis 缓存机制