-3

How can I turn this string:

a = "1 + 2 + 3"

into an operation which will output 6? Is there any code made for this?

ruohola
  • 21,987
  • 6
  • 62
  • 97
Deniz Kaya
  • 27
  • 3
  • Does this answer your question? [Convert string to calculable operation](https://stackoverflow.com/questions/12939308/convert-string-to-calculable-operation) – Tugay Jan 23 '21 at 22:29

1 Answers1

1

You can use eval:

>>> a = "1 + 2 + 3"
>>> eval(a)
6
ruohola
  • 21,987
  • 6
  • 62
  • 97