Python Convert Float to String

  1. Python Convert Float to String Using str() Function
  2. Python Convert Float to String Using repr() Function

This tutorial will explain multiple ways to convert a float to a string in Python. We can convert a float to a string using the str() and repr() functions.

Python Convert Float to String Using str() Function

The str() method takes an object as input and converts it into a string type. The example code below demonstrates how to use the str() function to convert a float to string in Python.

my_float = 0.125

string = str(my_float)
print(string)
print(type(string))

Output:

0.125
<class 'str'>

Python Convert Float to String Using repr() Function

The repr() method converts an object into a printable string. The example code below demonstrates how the repr() function converts a float to a string in Python.

my_float = 0.125

string = repr(my_float)
print(string)
print(type(string))

Output:

0.125
<class 'str'>
Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Python Float

  • Truncate Float in Python
  • Related Article - Python String

  • Remove Special Characters From the String in Python