Funkce Python bytes() .
Příklad
Vrátí pole 4 bajtů:
x = bytes(4)
Definice a použití
Funkce bytes()
vrací objekt typu bytes.
Může převádět objekty na objekty typu bytes nebo vytvářet prázdné objekty typu bytes zadané velikosti.
Rozdíl mezi bytes()
a
bytearray()
je ten, že
bytes()
vrací objekt, který nelze upravit, a
bytearray()
vrací objekt, který lze upravit.
Syntax
bytes(x, encoding, error)
Hodnoty parametrů
Parameter | Description |
---|---|
x | A source to use when creating the bytes object. If it is an integer, an empty bytes object of the specified size will be created. If it is a String, make sure you specify the encoding of the source. |
encoding | The encoding of the string |
error | Specifies what to do if the encoding fails. |