Easy Tutorial
❮ Ref Set Update Python String Startswith ❯

Python eval() Function

Python Built-in Functions


Description

The eval() function is used to execute a string expression and return the value of the expression.

Syntax

Here is the syntax for the eval() method:

eval(expression[, globals[, locals]])

Parameters

Return Value

Returns the result of the expression evaluation.


Examples

The following examples demonstrate the use of the eval() method:

>>> x = 7
>>> eval('3 * x')
21
>>> eval('pow(2,2)')
4
>>> eval('2 + 2')
4
>>> n = 81
>>> eval("n + 4")
85

Python Built-in Functions

❮ Ref Set Update Python String Startswith ❯