Search code examples
pythonstringcommandexecute

How to execute a statement which was a string initially


My question is about how to make the compiler treats my string as an executable statement, consider my string mystr='1+2+3', now the question is what's the code to put in function func so when I execute the following command func(mystr) I get 6 on my screen.


Solution

  • eval(mystr).

    Documentation here.