Python eval() function is used to evaluate a passed expression and runs python expression (code) within the program. The eval()
method returns the result evaluated from the expression.
eval(expression, globals, locals)
Python eval() function
A simple example code evaluates the specified expression.
x = 1
print(eval('x + 1'))
res = eval("sum([8, 16, 32])")
print(res)
Output:
Do comment if you have any doubts or suggestions on this Python function topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.