Python str() Funzione
Esempio
Converti il numero 3.5 in una stringa:
x =
str(3.5)
Definizione e utilizzo
La str()
funzione converte il valore specificato in una stringa.
Sintassi
str(object, encoding=encoding, errors=errors)
Valori dei parametri
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 |
Altri esempi
Esempio
Converti una stringa in un numero intero:
x =
int("12")