Python eval() Function

Example

Calculate the expression 'print(78)':

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

Running Instance

Definition and Usage

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

Syntax

eval(expression, globals, locals)

Parameter Value

Parameter Description
expression String, which will be evaluated as Python code.
globals Optional. A dictionary containing global parameters.
locals Optional. A dictionary containing local parameters.