[Tutor] Evaluating a string expression

Serdar Tumgoren zstumgoren at gmail.com
Thu Nov 5 14:21:15 CET 2009

> I would like to know how would I evaluate a string expression in python.
> For example, if i say:
>>>> a = "3*2"
> I want to do something to evaluate the variable 'a' to give me 6. How
> can I do this?

I think the "eval" built-in function is what you're after:

>>> a = "3*2"
>>> eval(a)


More information about the Tutor mailing list