[Tutor] Evaluating a string expression

Mkhanyisi Madlavana mmadlavana at gmail.com
Thu Nov 5 14:22:49 CET 2009


Thanks!

2009/11/5 Serdar Tumgoren <zstumgoren at gmail.com>
>
> > 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)
> 6
>
> http://docs.python.org/library/functions.html


More information about the Tutor mailing list