PyDocs

Nav

Python Runtime Services

eval

builtins

function
  • eval(source, /, globals=None, locals=None)
Evaluate the given source in the context of globals and locals.

The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
Changed in 3.13, 3.15
  • 3.13: The globals and locals arguments can now be passed as keywords.
  • 3.13: The semantics of the default locals namespace have been adjusted as described for the locals() builtin.
  • 3.15: globals can now be a frozendict.
1 Example
>>> x = 1
>>> eval('x+1')
2
from the Python docs
See Also
No see-alsos for builtins/eval
0 Notes
No notes for eval