Which of the following function convert a string to a float in python?
In this article, we will see which function can be used to convert a string to float in Python.
We can convert a string to float in Python using float()
function. It’s a built-in function to convert an object to floating point number.
# convert string to # float using float() s1 = '3.3121' s2 = '4.46586' f1 = float(s1) f2 = float(s2) print(type(f1)) print(type(f2)) print(f1, f2) print(f1 + f2)
Output:
<class 'float'> <class 'float'> 3.3121 4.46586 7.77796
Subscribe
Login
Please login to comment
0 Discussion