THE WORLD'S LARGEST WEB DEVELOPER SITE

Python eval() Function

❮ Built-in Functions


Example

Evaluate the expression 'print(55)':

x = 'print(55)'
eval(x)
Run example »

Definition and Usage

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


Syntax

eval(expression, globals, locals)

Parameter Values

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

❮ Built-in Functions