• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答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函數詳細介紹

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

    Python內置bin函數詳細介紹

    Python內置bin函數詳細介紹:英文文檔: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函數詳細介紹:英文文檔: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. 將一個整形數字轉換成二進制字符串

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

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

    2.1 如果對象不是整數,則報錯

    >>> 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__方法,但返回值不是整數,報錯

    >>> 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__方法,且返回值是整數,將__index__方法返回值轉換成二進制字符串

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

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

    文檔

    Python內置bin函數詳細介紹

    Python內置bin函數詳細介紹:英文文檔: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
    主站蜘蛛池模板: 精品国产第1页| 亚欧无码精品无码有性视频 | 少妇亚洲免费精品| 国产精品久久成人影院| 中文字幕精品久久久久人妻| 精品久久久久久无码人妻蜜桃| 亚洲精品视频在线| 精品国产一区二区三区久久 | 久久亚洲国产午夜精品理论片 | 精品久久久久中文字幕日本| 久久久久99精品成人片| 91精品国产色综久久| 国产一区二区精品久久| 精品欧洲av无码一区二区三区| 国产精品麻豆VA在线播放| 99久久精品毛片免费播放| 亚洲欧洲国产精品香蕉网| 亚洲精品无码久久毛片| 欧美成人精品欧美一级乱黄码| 国内精品99亚洲免费高清| 91精品国产福利在线观看| 国产精品久久永久免费| 国产精品第12页| 8AV国产精品爽爽ⅴa在线观看| 精品国产一区二区三区久久久狼| 亚洲精品国产成人片| 中文字幕精品无码一区二区| 亚洲电影日韩精品| 午夜成人精品福利网站在线观看 | 久久国产精品久久国产精品| 538国产精品一区二区在线| 精品国产一区二区三区无码| 精品人妻中文字幕有码在线| 精品免费人成视频app| 国产成人精品日本亚洲网站| 国产精品jizz视频| 国产精品九九九久久九九| 亚洲国产精品第一区二区| 91精品国产自产在线老师啪| www夜片内射视频日韩精品成人| 国产999精品久久久久久|