Python divmod() 函數

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)

Python 內置函數 Python 內置函數