We cannot use mathematical operations on a string in Python programming. To do so, we have to convert a string containing numeric value into a float or any number. Most of the time we get data through text field or by reading a text file. Usually, entered data is received as a string. For doing mathematical or statistical calculations, we have to convert or parse the string (“numeric value in a string”) to a numeric value such as float.
Look at the following example for more understanding.
Example # 1
# Declare a variable
str = "555.55"
# Now parse/convert a string into float.
# Declare a variables
str1 = "260.888"
str2 = "360.888"
# str1 and str2 both are string
# to perform numeric calculation we have to convert them
# in a numeric such as float.
# Adding two strings after converting into floats.
print(float(str1) + float(str2))