I take the current exchange rate from the bank’s website as a string and I want to convert this string into a number for further calculations and I want to do it as beautifully as possible.
How to convert the string 77,4651 $ to 77.4651 in float format without using func ‘replace’?
>Solution :
Use float regular expression to make sure, that you get the float number
txt = "77.4651 $"
x = float(re.search("[-+]?[0-9]*(?:\.?[0-9]*)[1]", txt).string)
or less safe split by spaces
float("77.4651 $".split("\s+")[0])