Python bytearray() Function

Example

Returns an array of 5 bytes:

x = bytearray(5)

Running Instance

Definition and Usage

The bytearray() function returns a bytearray object.

It can convert an object to a bytearray object or create an empty byte array object of a specified size.

Syntax

bytearray(x, encoding, error)

Parameter Value

Parameter Description
x

Resources used when creating a bytearray object

If it is an integer, it will create an empty bytearray object of the specified size.

If it is a string, make sure to specify the encoding of the resource.

encoding Encoding of Strings
error Specify what to do if encoding fails.

Related Pages

Reference Manual:bytes() Function