Python eval() function
Python eval() function The eval() function in Python is used to evaluate the given expression. If the specified expression is a legal Python statement, it will be executed. Syntax
eval(expression, globals=None, locals=None)
Parameter
expression: This parameter represents a String, that will be evaluated as Python code globals: It is an optional parameter that represents a dictionary containing global parameters locals: It is also an optional parameter that represents a dictionary containing local parametersReturn
This function returns the result of the evaluated expression Example 1# Python Program explaining # eval() function x = 'print(565)' eval(x)Output
565Example 2
# Python Program explaining # eval() function x = 11 print(eval('x==11')) print(eval('x+2'))Output
True 13