首頁 >後端開發 >Python教學 >python函數 - bytearray

python函數 - bytearray

高洛峰
高洛峰原創
2016-10-17 15:34:461307瀏覽

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

中文說明:

bytearray([source [, encoding [, errors]]])傳回一個byte數組。 Bytearray類型是一個可變的序列,且序列中的元素的取值範圍為 [0 ,255]。


參數source:


如果source為整數,則傳回長度為source的初始化陣列;


節序列;


如果source為可迭代類型,則元素必須為[0 ,255]中的整數;


如果source為與buffer介面一致的對象,則此物件也可以用於初始化bytearray.。


版本:在python2.6後新引入,在python3中同樣可以使用!


英文說明:

Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 The optional source parameter can be used to initialize the array in a few different ways: strive ordic​​I sowIoo​​hih ways:IustI ​​necto ways 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 itialby 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 ingers in xterable, it must be an iterable of ingers an iterable 256, which are used as the initial contents of the array.

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

New in version 2.6.

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn