Python bytes() Function
Definition and Usage
The bytes() function returns a byte object.
It can convert an object to a byte object, or create an empty byte object of the specified size.
The difference between bytes() and bytearray() is that bytes() returns an immutable object, while bytearray() returns a mutable object.
Syntax
bytes(x, encoding, error)
Parameter Value
Parameter | Description |
---|---|
x |
Resource 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 that the encoding of the resource is specified. |
encoding | String Encoding |
error | Specify what to do if encoding fails. |
Related Pages
Reference Manual:bytearray() Function