Python standard library: built-in function bytearray ([source [, encoding [, errors]), pythonbytearray

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.