国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答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內置bytearray函數詳細介紹

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

Python內置bytearray函數詳細介紹

Python內置bytearray函數詳細介紹:英文文檔:class bytearray([source[, encoding[, errors]]])Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. It has mo
推薦度:
導讀Python內置bytearray函數詳細介紹:英文文檔:class bytearray([source[, encoding[, errors]]])Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. It has mo

英文文檔:

class bytearray([source[, encoding[, errors]]])

Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has, see Bytes and Bytearray Operations.

The optional source parameter can be used to initialize the array in a few different ways:

  • If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str.encode().

  • If it is an integer, the array will have that size and will be initialized with null bytes.

  • If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.

  • If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents of the array.

  • Without an argument, an array of size 0 is created.

    說明:

    1. 返回值為一個新的字節數組

    2. 當3個參數都不傳的時候,返回長度為0的字節數組

    >>> b = bytearray()
    >>> b
    bytearray(b'')
    >>> len(b)
    0

    3. 當source參數為字符串時,encoding參數也必須提供,函數將字符串使用str.encode方法轉換成字節數組

    >>> bytearray('中文')
    Traceback (most recent call last):
     File "<pyshell#48>", line 1, in <module>
     bytearray('中文')
    TypeError: string argument without an encoding
    >>> bytearray('中文','utf-8')
    bytearray(b'xe4xb8xadxe6x96x87')

    4. 當source參數為整數時,返回這個整數所指定長度的空字節數組

    >>> bytearray(2)
    bytearray(b'x00x00')
    >>> bytearray(-2) #整數需大于0,使用來做數組長度的
    Traceback (most recent call last):
     File "<pyshell#51>", line 1, in <module>
     bytearray(-2)
    ValueError: negative count

    5. 當source參數為實現了buffer接口的object對象時,那么將使用只讀方式將字節讀取到字節數組后返回

    6. 當source參數是一個可迭代對象,那么這個迭代對象的元素都必須符合0 <= x < 256,以便可以初始化到數組里

    >>> bytearray([1,2,3])
    bytearray(b'x01x02x03')
    >>> bytearray([256,2,3]) #不在0-255范圍內報錯
    Traceback (most recent call last):
     File "<pyshell#53>", line 1, in <module>
     bytearray([256,2,3])
    ValueError: byte must be in range(0, 256)

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

    文檔

    Python內置bytearray函數詳細介紹

    Python內置bytearray函數詳細介紹:英文文檔:class bytearray([source[, encoding[, errors]]])Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. It has mo
    推薦度:
    標簽: 函數 python byte
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 国产高清在线免费 | 最新国产在线 | 天天操综 | 欧美性xxxxx 欧美视频亚洲视频 | 91免费高清视频 | 精品不卡 | 亚欧成人毛片一区二区三区四区 | 碰91精品国产91久久婷婷 | 国产精品免费观看 | 成人免费久久精品国产片久久影院 | 91麻豆免费视频 | 97成人免费视频 | 毛片资源 | 日本亲与子乱ay中文 | 欧美在线视频网 | 国产国语一级毛片中文 | 国产欧美精品一区二区三区四区 | 国产视频一区二区三区四区 | 欧美网站在线观看 | 日本v片免费一区二区三区 欧洲精品欧美精品 | 国产精品第 | 欧美精品亚洲精品日韩专区va | 欧美日韩啪啪 | 亚洲最新视频在线观看 | 国产女人在线视频 | 91精品国产99久久 | 99在线视频观看 | 劲爆欧美精品13页 | 国产精品久久久久久一区二区 | 日韩精品成人免费观看 | 亚洲伦| 97精品国产91久久久久久久 | 欧美精品一区二区三区在线 | 国产三级福利 | 成人一区在线 | 久久久久久久国产精品毛片 | 国产精品va在线观看无 | 黄色网站视频免费 | 亚洲精品综合久久中文字幕 | 又粗又硬又大又深又爽动态图 | 精品视频在线观看视频免费视频 |