Python eval() function

instance

Calculate the expression 'print(78)':

x = 'print(78)'
eval(x)

run instance

definition and usage

The eval() function calculates the specified expression, if the expression is a valid Python statement, it will be executed.

syntax

eval(expression, globals, locals)

parameter value

parameter description
expression A string that will be evaluated as Python code.
globals Optional. A dictionary containing global parameters.
locals Optional. A dictionary containing local parameters.