To convert a list of strings to a list of floats in Python, you can use list comprehension along with the float()
constructor to parse each string as a float.
In this example,
string_list
.float()
constructor to parse it as a float.string_list = ["1.1", "2.2", "3.3", "4.4", "5.5"]
float_list = [float(x) for x in string_list]
print(float_list)
[1.1, 2.2, 3.3, 4.4, 5.5]
In this tutorial, we learned How to Convert a List of Strings to a List of Floats in Python language with well detailed examples.