您現在所在的位置:首頁 >學習資源 > Python全棧+人工智能入門教材 > Python基礎入門教程54:Pytho divmod() 函數
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)