How to convert "12.3+13.5" to float in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

How to convert "12.3+13.5" to float in python?

29th Nov 2021, 8:05 AM
Lalitha Prasanna
3 Answers
29th Nov 2021, 8:07 AM
MATOVU CALEB
MATOVU CALEB - avatar
+ 1
The exec function can execute a string as though it is Python code. exec("x=" + "12.3+13.5") print(x) The numbers in the string can be separated out and then converted from string into float. x, y = "12.3+13.5".split('+', 1) print(float(x) + float(y))
29th Nov 2021, 8:24 AM
Brian
Brian - avatar
0
Please always tag the language you're asking about. https://code.sololearn.com/W3uiji9X28C1/?ref=app
29th Nov 2021, 8:32 AM
Simon Sauter
Simon Sauter - avatar