Home >>Python Built-in Functions >Python bytearray() Function
Python bytearray() function is used to return a bytearray object. It can convert a given input objects into bytearray objects or create empty bytearray object of the given size.
Syntax:bytearray(x, encoding, error)
Parameter | Description |
---|---|
x | This parameter defines a source to use when creating the bytearray object. |
encoding | This parameter defines the encoding of the string. |
error | This parameter defines what to do if the encoding fails. |
x = bytearray(8) print(x)
x = bytearray('Jerry','utf-16') print(x)