<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Python內置bin函數(shù)詳細介紹

        來源:懂視網 責編:小采 時間:2020-11-27 14:25:13
        文檔

        Python內置bin函數(shù)詳細介紹

        Python內置bin函數(shù)詳細介紹:英文文檔:bin(x) Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that
        推薦度:
        導讀Python內置bin函數(shù)詳細介紹:英文文檔:bin(x) Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that

        英文文檔:

        bin(x)

        Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

        說明:

        1. 將一個整形數(shù)字轉換成二進制字符串

        >>> b = bin(3) 
        >>> b
        '0b11'
        >>> type(b) #獲取b的類型
        <class 'str'>

        2. 如果參數(shù)x不是一個整數(shù),則x必須定義一個 __index__() 方法,并且方法返回值必須是整數(shù)。

        2.1 如果對象不是整數(shù),則報錯

        >>> class A:
         pass
        
        >>> a = A()
        >>> bin(a) 
        Traceback (most recent call last):
         File "<pyshell#15>", line 1, in <module>
         bin(a)
        TypeError: 'A' object cannot be interpreted as an integer

        2.2 如果對象定義了__index__方法,但返回值不是整數(shù),報錯

        >>> class B:
         def __index__(self):
         return "3"
        
        >>> b = B()
        >>> bin(b)
        Traceback (most recent call last):
         File "<pyshell#21>", line 1, in <module>
         bin(b)
        TypeError: __index__ returned non-int (type str)

        2.3 對象定義了__index__方法,且返回值是整數(shù),將__index__方法返回值轉換成二進制字符串

        >>> class C:
         def __index__(self):
         return 3
        
        >>> c = C()
        >>> bin(c)
        '0b11'

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Python內置bin函數(shù)詳細介紹

        Python內置bin函數(shù)詳細介紹:英文文檔:bin(x) Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that
        推薦度:
        標簽: 介紹 詳解 簡介
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 国产成人综合亚洲| 亚洲国产精品综合久久2007| 精品国产亚洲一区二区三区在线观看 | 免费一级毛片不卡不收费| 亚洲夂夂婷婷色拍WW47| 午夜无遮挡羞羞漫画免费| 亚洲一级片在线播放| 99re视频精品全部免费| 亚洲精品无码久久久久久久 | 中文字幕不卡免费视频| 亚洲午夜无码久久久久| 丝瓜app免费下载网址进入ios| 亚洲精品乱码久久久久久久久久久久 | 亚洲一区在线免费观看| 亚洲国产成a人v在线观看 | 中文在线观看永久免费| 日本亚洲视频在线| 亚洲精品视频在线观看免费| 国产男女猛烈无遮挡免费视频网站| 亚洲精品久久无码| 免费看国产曰批40分钟| a级在线免费观看| 亚洲视频在线观看视频| 成全在线观看免费观看大全| 四虎1515hm免费国产| 久久精品无码免费不卡| 亚洲精品国产福利在线观看| 女人被男人桶得好爽免费视频| 日韩国产精品亚洲а∨天堂免| 国产亚洲精品免费视频播放 | 本道天堂成在人线av无码免费| 亚洲AV综合色一区二区三区| aa级一级天堂片免费观看| 一级做a爰片久久毛片免费看| 亚洲国产第一站精品蜜芽| 青草草色A免费观看在线| 日韩免费码中文在线观看| 亚洲精品视频久久| gogo全球高清大胆亚洲| 亚州免费一级毛片| 久久精品无码免费不卡|