Home > Backend Development > Python Tutorial > python function - bytearray

python function - bytearray

高洛峰
Release: 2016-10-17 15:34:46
Original
1306 people have browsed it

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

Chinese description:

bytearray([source [, encoding [, errors]]]) returns a byte array. The Bytearray type is a variable sequence, and the value range of the elements in the sequence is [0,255].


Parameter source:


If source is an integer, return an initialization array with the length of source;


If source is a string, convert the string into a word according to the specified encoding Section sequence;


If the source is an iterable type, the element must be an integer in [0,255];


If the source is an object consistent with the buffer interface, this object can also be used To initialize bytearray..


Version: Newly introduced after python2.6, it can also be used in python3!


English description:

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:

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template