新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythondivmod()
在 Python divmod 中,函數(shù)取兩個數(shù)字,第一個除以第二個,返回商和提醒的元組。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信平臺小程序開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了寶山免費建站歡迎大家使用!
**divmod(dividend,divisor)** #The dividend will be divided by
divmod()參數(shù):
該函數(shù)采用兩個強制參數(shù),第一個參數(shù)被視為被除數(shù),第二個參數(shù)被視為除數(shù)。第二個參數(shù)不能為零,因為
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 紅利 | 一個數(shù)字,將被劃分 | 需要 |
| 除數(shù) | 用來除的數(shù)字。該數(shù)字不能為零 | 需要 |
divmod()返回值
該函數(shù)總是根據(jù)輸入返回商數(shù)和余數(shù)的元組。這兩個參數(shù)都是強制性的。
| 投入 | 返回值 | | 被除數(shù)和除數(shù) | 商數(shù)和提醒的元組 | | 字符串作為第一個參數(shù),編碼作為第二個參數(shù) | 編碼為字節(jié)的字符串 | | 可重復的 | 字節(jié)與可迭代的大小相同 | | 無參數(shù) | 創(chuàng)建沒有元素的字節(jié)對象 |
Python 中divmod()方法的示例
示例 1:將整數(shù)作為參數(shù)傳遞
result = divmod(2,1)
print(“Divmod of 2 and 1 are :”, result)
result = divmod(3.5,2.5)
print(“Divmod of 3.5 and 2.5 are :”, result)
輸出:
Divmod of 2 and 1 are : (2, 0)
Divmod of 3.5 and 2.5 are : (1.0, 1.0)
示例 2:將浮點作為參數(shù)傳遞
print('divmod(8.0, 3) = ', divmod(8.0, 3))
print('divmod(3, 8.0) = ', divmod(3, 8.0))
print('divmod(7.5, 2.5) = ', divmod(7.5, 2.5))
print('divmod(2.6, 0.5) = ', divmod(2.6, 0.5))
輸出:
divmod(8.0, 3) = (2.0, 2.0)
divmod(3, 8.0) = (0.0, 3.0)
divmod(7.5, 2.5) = (3.0, 0.0)
divmod(2.6, 0.5) = (5.0, 0.10000000000000009) 文章標題:創(chuàng)新互聯(lián)Python教程:Pythondivmod()
URL標題:http://m.fisionsoft.com.cn/article/dhehojd.html


咨詢
建站咨詢
