做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程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
    主站蜘蛛池模板: 天峻县| 肥乡县| 兰州市| 怀化市| 吴堡县| 南宫市| 宜兰县| 江城| 辽源市| 永丰县| 崇州市| 昂仁县| 卓尼县| 玉门市| 固原市| 延长县| 三穗县| 武鸣县| 始兴县| 阜阳市| 邛崃市| 高清| 东辽县| 富民县| 赤水市| 辉南县| 西昌市| 西平县| 准格尔旗| 台南县| 广东省| 佛山市| 收藏| 盈江县| 鹤壁市| 扬中市| 宣化县| 黔西县| 社会| 花垣县| 洛川县|