python内置函数 divmod()


先来看一下builtins.py中的代码: 

def divmod(x, y): # known case of builtins.divmod
    """ Return the tuple (x//y, x%y).  Invariant: div*y + mod == x. """
    return (0, 0)

 

python divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(x//y, x%y)。 

>>> divmod(27,5)
(5, 2)
>>> divmod(6,6)
(1, 0)
>>> divmod(6,3.0)
(2.0, 0.0)

>>> divmod(1+2j,1+2j)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't take floor or mod of complex number.
>>> 

  

有些python版本不允许处理复数。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM