Перейти к содержанию

Python eval() built-in function

Python eval() built-in function

From the Python 3 documentation The arguments are a string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object.

Examples

>>> eval('1 + 4')
# 5

>>> eval('print("Hello World!")')
# Hello World!

>>> x = 10
>>> eval('x == 10')
# True