The eval() function in python is used to execute a string expression and return the value of the expression.
The following is the syntax of the eval() method:
eval(expression[, globals[, locals]])
Parameters
expression -- Expression.
globals -- Variable scope, global namespace, if provided, must be a dictionary object.
locals -- Variable scope, local namespace, if provided, can be any mapping object.
Return value
Returns the expression calculation result.
The following shows an example of using the eval() method:
>>>x = 7 >>> eval( '3 * x' ) 21 >>> eval('pow(2,2)') 4 >>> eval('2 + 2') 4 >>> n=81 >>> eval("n + 4") 85
Related recommendations: "Python Tutorial"
The above is the detailed content of What is eval in python. For more information, please follow other related articles on the PHP Chinese website!