英文文档:

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

Python内置函数(17)——divmod的更多相关文章

  1. Python内置函数(17)——chr

    英文文档: chr(i) Return the string representing a character whose Unicode code point is the integer i. F ...

  2. Python内置函数(2)——divmod

    英文文档: divmod(a, b) Take two (non complex) numbers as arguments and return a pair of numbers consisti ...

  3. 17.python内置函数2

    python内置函数1:https://www.cnblogs.com/raitorei/p/11813694.html # max,min高级玩法 # l=[1,3,100,-1,2] # prin ...

  4. 【转】python 内置函数总结(大部分)

    [转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...

  5. python 内置函数总结(大部分)

    python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...

  6. Python之路(第八篇)Python内置函数、zip()、max()、min()

    一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算,如果全部都是true,就返回true, 但是如果是空字符串.空列表也返回t ...

  7. python内置函数详细介绍

    知识内容: 1.python内置函数简介 2.python内置函数详细介绍 一.python内置函数简介 python中有很多内置函数,实现了一些基本功能,内置函数的官方介绍文档:    https: ...

  8. 【286】◀▶ Python 内置函数说明

    参考: Python 内置函数 01   abs() 返回数字的绝对值. 02   all() 用于判断给定的可迭代参数 iterable 中的所有元素是否不为 0.''.False 或者 itera ...

  9. Python之路Python内置函数、zip()、max()、min()

    Python之路Python内置函数.zip().max().min() 一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算, ...

随机推荐

  1. 2、Linux常用功能

    防火墙的基本用法 - 启动: systemctl start firewalld - 关闭: systemctl stop firewalld - 查看状态: systemctl status fir ...

  2. 022 包含min函数的栈

    1.题目 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). 2.分析 最初想法是定义一个成员变量min来存放最小元素,但是当最小元素弹出后,min ...

  3. MDK5 设置project targents?如何实现的有知道的请共享一下谢谢感激不尽!!!!

    就在刚刚阅读NRF51822相关的文档时遇到问题,官方给出了一份模板,我从我安装的example中找出了官方的列程,看到是soft config的方式配置的,于是根据列程的配置,自己新建了一个工程之后 ...

  4. Navicat Premium 12.1.12.0安装与激活

    转载自:Navicat Premium 12.1.12.0安装与激活 作者:丿记忆灬永殇丨 链接:https://www.jianshu.com/p/5f693b4c9468 navicat12112 ...

  5. SpringCloud使用Sofa-lookout监控(基于Eureka)

    本文介绍SpringCloud使用Sofa-lookout,基于Eureka服务发现. 1.前景 本文属于是前几篇文章的后续,其实一开始感觉这个没有什么必要写的,但是最近一个朋友问我关于这个的问题,所 ...

  6. mysql远程连接/访问速度慢的解决方案

    连接阿里云服务器上的数据库,速度很慢 账户密码正确 已关闭防火墙 修改 /etc/my.cnf,添加配置skip-name-resolve [mysqld] skip-name-resolve 在连接 ...

  7. Win10 安装Oracle11g2、配置PL/SQL Developer11环境

    Oracle11g2的下载地址(下载以下两个压缩包,解压后得到两个oracle目录,放到一起就得到完整的安装文件了): 1.Oracle11g2: oracle-part-1 oracle-part- ...

  8. pycharm下虚拟环境建立,django项目建立等情况说明

  9. 新装云服务器没有iptables 文件,并且无法通过service iptables save操作

    在安装zookeeper时,需要放开端口2181 按照视频教程在 /etc/sysconfig/ 下对iptables 文件进行编辑,但是该目录下没有此文件 通过强行写iptables -P  OUT ...

  10. JS浏览器兼容问题

    一.JS与DOM的兼容性: (一) DOM节点的访问: 1.以前对DOM节点访问一般用“document.All.元素ID属性值”或者“document.元素ID属性值”这种简化的方法,在FireFo ...