Next / Previous / Contents / Shipman's homepage

21.6. eval(): Evaluate an expression in source form

This function evaluates a Python expression from a string. Example:

>>> cent=100
>>> eval('cent**3')

If you want to evaluate the expression using different name environments, refer to the official documentation. For related features, see also Section 21.7, “execfile(): Execute a Python source file” and Section 22.4, “The exec statement: Execute Python source code”.