Función Python bytes()
Ejemplo
Devuelve una matriz de 4 bytes:
x = bytes(4)
Definición y uso
La bytes()
función devuelve un objeto de bytes.
Puede convertir objetos en objetos de bytes, o crear objetos de bytes vacíos del tamaño especificado.
La diferencia entre bytes()
y
bytearray()
es que
bytes()
devuelve un objeto que no se puede modificar y
bytearray()
devuelve un objeto que se puede modificar.
Sintaxis
bytes(x, encoding, error)
Valores paramétricos
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. |