Python standard library: built-in function bytearray ([source [, encoding [, errors]), pythonbytearray
Returns a new byte array. The elements in this array are variable, and the value range of each element is 0 <= x <256. You can use the "Byte and byte array operations" section to view the content of the byte array. The following describes several special usage methods:
1. If source is a string, you must specify the encoding of endcoding to convert it to a proper byte for storage.
2. If source is an integer, the array is initialized to a null byte.
3. If source is an object with a buffer interface, the read-only interface is initially included in the array.
4. If source is an iteration object, all elements of this iteration object must conform to 0 <= x <256, so that they can be initialized to the array.
If no parameter is input, the array is initialized with 0 elements by default.
Example:
# Bytearray () function a = bytearray ('2017 Shenzhen ', 'utf-8') print (a) B = bytearray () print (B) c = [1234, 8] print (bytearray (c ))
The output result is as follows:
Bytearray (B '1234 \ xe6 \ xb7 \ xb1 \ xe5 \ x9c \ xb3 ')
Bytearray (B '')
Bytearray (B '\ x01 \ x04 \ x05 \ x07 \ x08 ')
Cai junsheng QQ: 9073204 Shenzhen
In pthon, bytearray ([source [, encoding [, errors]) explains what are the three variables behind it?
It is written in the document. Let's take a look at several situations.
How does python convert bytearray to a string?
Str (bytearray, encoding)