Função Python bytes()
Exemplo
Retorna um array de 4 bytes:
x = bytes(4)
Definição e uso
A bytes()
função retorna um objeto bytes.
Ele pode converter objetos em objetos bytes ou criar objetos bytes vazios do tamanho especificado.
A diferença entre bytes()
e
bytearray()
é que
bytes()
retorna um objeto que não pode ser modificado e
bytearray()
retorna um objeto que pode ser modificado.
Sintaxe
bytes(x, encoding, error)
Valores de parâmetro
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. |