Python Convert Float to String
Podemos converter um flutuador em uma string usando as funções str()
e repr()
.
Usando função str()
Sintaxe
str(Object)
O método str()
pega um objeto como entrada e o converte em um tipo de string.
floatNum = 0.432 string = str(floatNum) print(string) print(type(string))
Saída
0.432 <class 'str'>
Usando função repr()
Sintaxe
repr(obj)
O método repr()
pega um objeto como entrada e o converte em uma sequência imprimível.
floatNum = 0.432 string = repr(floatNum) print(string) print(type(string))
Saída
0.432 <class 'str'>