Python基礎 Python教程 Python入門
Python 內置函數
python 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)