Fonction Python bytes()
Exemple
Renvoie un tableau de 4 octets :
x = bytes(4)
Définition et utilisation
La bytes()
fonction renvoie un objet bytes.
Il peut convertir des objets en objets bytes ou créer des objets bytes vides de la taille spécifiée.
La différence entre bytes()
et
bytearray()
est que
bytes()
renvoie un objet qui ne peut pas être modifié et
bytearray()
renvoie un objet qui peut être modifié.
Syntaxe
bytes(x, encoding, error)
Valeurs des paramètres
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. |