OneBite.Dev - Coding blog in a bite size

convert variable from float to string in python

Code snippet on how to convert variable from float to string in python

value = 10.5
string = str(value)

This code will convert a value of type float (decimal number) to a string. The first line defines a variable called “value” and assigns a number 10.5 (float type) to it. The second line then converts the float type to a string by using the built-in Python str() method and assigning it to a new variable called “string”.

python