Python eval() FunctionPython Functions

Difficulty Level:
Difficulty Level:

The Eval() function is used to execute a string expression as Python code and return the value of the expression execution.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

x = 11
print(eval( '3 * x' ))

print(eval('pow(2,4)'))

n = 11
print( eval("n + 4"))

Output:

33
16
15

Syntax

eval(expression)

Parameters

The method takes string expression as an input parameter.

Return Value

Return the result of expression execution.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us