亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python 中的divmod數(shù)字處理函數(shù)淺析

 更新時間:2017年10月17日 11:53:50   投稿:mrr  
這篇文章主要介紹了python divmod數(shù)字處理函數(shù)的相關(guān)資料,感興趣的朋友一起看看吧

divmod(a,b)函數(shù)

中文說明:

divmod(a,b)方法返回的是a//b(除法取整)以及a對b的余數(shù)

返回結(jié)果類型為tuple

參數(shù):

a,b可以為數(shù)字(包括復(fù)數(shù))

版本:

在python2.3版本之前不允許處理復(fù)數(shù),這個大家要注意一下

英文說明:

Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division. With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (a // b, a % b). For floating point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that. In any case q * b + a % b is very close to a, if a % b is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b).

Changed in version 2.3: Using divmod() with complex numbers is deprecated.

python代碼實(shí)例:

>>> divmod(9,2)
(4, 1)
>>> divmod(11,3)
(3, 2)
>>> divmod(1+2j,1+0.5j)
((1+0j), 1.5j)

PS:Python標(biāo)準(zhǔn)庫:內(nèi)置函數(shù)divmod(a, b)

本函數(shù)是實(shí)現(xiàn)a除以b,然后返回商與余數(shù)的元組。如果兩個參數(shù)a,b都是整數(shù),那么會采用整數(shù)除法,結(jié)果相當(dāng)于(a//b, a % b)。如果a或b是浮點(diǎn)數(shù),相當(dāng)于(math.floor(a/b), a%b)。

例子:

#divmod() 
print('divmod(2, 4):', divmod(2, 4)) 
print('divmod(28, 4):', divmod(28, 4)) 
print('divmod(27, 4):', divmod(27, 4)) 
print('divmod(25.6, 4):', divmod(25.6, 4)) 
print('divmod(2, 0.3):', divmod(2, 0.3)) 

輸出結(jié)果如下:

divmod(2, 4): (0, 2)
divmod(28, 4): (7, 0)
divmod(27, 4): (6, 3)
divmod(25.6, 4): (6.0, 1.6000000000000014)
divmod(2, 0.3): (6.0, 0.20000000000000007)

總結(jié)

以上所述是小編給大家介紹python divmod數(shù)字處理函數(shù)淺析,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

您可能感興趣的文章:

相關(guān)文章

  • Python os模塊學(xué)習(xí)筆記

    Python os模塊學(xué)習(xí)筆記

    這篇文章主要介紹了Python os模塊學(xué)習(xí)筆記,本文總結(jié)了OS模塊的常用方法、實(shí)用方法,并給出了兩個使用實(shí)例,需要的朋友可以參考下
    2015-06-06
  • Python實(shí)現(xiàn)定時備份mysql數(shù)據(jù)庫并把備份數(shù)據(jù)庫郵件發(fā)送

    Python實(shí)現(xiàn)定時備份mysql數(shù)據(jù)庫并把備份數(shù)據(jù)庫郵件發(fā)送

    這篇文章主要介紹了Python實(shí)現(xiàn)定時備份mysql數(shù)據(jù)庫并把備份數(shù)據(jù)庫郵件發(fā)送的相關(guān)資料,需要的朋友可以參考下
    2018-03-03
  • Python實(shí)現(xiàn)向列表或數(shù)組添加元素

    Python實(shí)現(xiàn)向列表或數(shù)組添加元素

    Python中的列表是一種動態(tài)數(shù)組,可以存儲不同數(shù)據(jù)類型的元素,并提供多種方法進(jìn)行元素的添加和刪除,列表是Python中非常靈活和強(qiáng)大的數(shù)據(jù)結(jié)構(gòu),可以通過索引訪問、修改和操作列表中的元素,列表的創(chuàng)建十分簡單,只需使用方括號括起元素,并用逗號分隔
    2024-09-09
  • Django 前后臺的數(shù)據(jù)傳遞的方法

    Django 前后臺的數(shù)據(jù)傳遞的方法

    本篇文章主要介紹了Django 前后臺的數(shù)據(jù)傳遞的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • python的類方法和靜態(tài)方法

    python的類方法和靜態(tài)方法

    這篇文章主要介紹了python的類方法和靜態(tài)方法,以實(shí)例形式分析了Python中類方法和靜態(tài)方法的實(shí)現(xiàn)技巧與應(yīng)用方法,需要的朋友可以參考下
    2014-12-12
  • Python lambda函數(shù)基本用法實(shí)例分析

    Python lambda函數(shù)基本用法實(shí)例分析

    這篇文章主要介紹了Python lambda函數(shù)基本用法,結(jié)合實(shí)例較為詳細(xì)的分析了Python lambda函數(shù)的功能、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2018-03-03
  • 在Python的web框架中中編寫日志列表的教程

    在Python的web框架中中編寫日志列表的教程

    這篇文章主要介紹了在Python中編寫日志列表的教程,示例代碼基于Python2.x版本,需要的朋友可以參考下
    2015-04-04
  • Django如何配置mysql數(shù)據(jù)庫

    Django如何配置mysql數(shù)據(jù)庫

    這篇文章主要為大家詳細(xì)介紹了Django配置mysql數(shù)據(jù)庫的詳細(xì)步驟,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • 一文搞定Scrapy和Selenium整合使用

    一文搞定Scrapy和Selenium整合使用

    Scrapy和Selenium都是常用的Python爬蟲框架,下面這篇文章主要給大家介紹了關(guān)于如何通過一文搞定Scrapy和Selenium整合使用的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • Python PO設(shè)計(jì)模式的具體使用

    Python PO設(shè)計(jì)模式的具體使用

    這篇文章主要介紹了Python PO設(shè)計(jì)模式的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08

最新評論