String searching | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

String searching

I wish to type in a equation in one line, then analyze the string, dividing it in 3 variables, 2x float variables and 1 operator variable. I remember i read it somewhere but i cant remember at all!

19th May 2019, 1:53 PM
Rosenkilde
Rosenkilde - avatar
3 Answers
+ 4
You can also do this: a = '12.45 + 3.339' a1, op, a2 = a.split() # result: # a1 -> '12.45' # a2 -> '3.339' # op -> '+' Now it depends on what you are going to do with these results. An other possible way could be to split to list and then proceed.
19th May 2019, 2:45 PM
Lothar
Lothar - avatar
+ 3
You can use regex for this, it is described fully in the python3 tutorial
19th May 2019, 2:39 PM
Julian
Julian - avatar
0
Thanks for the answers! I guess its time to learn regular expression then 😁
19th May 2019, 3:20 PM
Rosenkilde
Rosenkilde - avatar