Fonction Python str()
Exemple
Convertissez le nombre 3,5 en une chaîne :
x =
str(3.5)
Définition et utilisation
La str()
fonction convertit la valeur spécifiée en une chaîne.
Syntaxe
str(object, encoding=encoding, errors=errors)
Valeurs des paramètres
Parameter | Description |
---|---|
object | Any object. Specifies the object to convert into a string |
encoding | The encoding of the object. Default is UTF-8 |
errors | Specifies what to do if the decoding fails |
Plus d'exemples
Exemple
Convertissez une chaîne en un entier :
x =
int("12")