exec()

Built-in FunctionPython 2.0+Advanced

Executes a string or code object as Python statements

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
code = "x = 42\nprint(x * 2)"
exec(code)

exec() is a built-in function that executes a string or code object as python statements.

Try in Playground

Tags

builtinfunctioncoremetaprogrammingdynamic

Related Items