Python bytes() Funzione
Esempio
Restituisce un array di 4 byte:
x = bytes(4)
Definizione e utilizzo
La bytes()
funzione restituisce un oggetto byte.
Può convertire oggetti in oggetti byte o creare oggetti byte vuoti della dimensione specificata.
La differenza tra bytes()
ed
bytearray()
è che
bytes()
restituisce un oggetto che non può essere modificato e
bytearray()
restituisce un oggetto che può essere modificato.
Sintassi
bytes(x, encoding, error)
Valori dei parametri
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. |