Home >Backend Development >Python Tutorial >What does eval mean in python?

What does eval mean in python?

青灯夜游
青灯夜游Original
2019-05-22 15:18:09245064browse

eval means "evaluation". It is a built-in function in python. It is used to execute a string expression and return the calculation result of the expression; that is, when assigning a variable, the right side of the equal sign means Written in string format, the return value is the result of this expression. Syntax "eval(expression[, globals[, locals]])".

What does eval mean in python?

The operating environment of this tutorial: windows7 system, python3 version, DELL G3 computer

eval() function

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

Syntax

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.

Example:

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

The above is the detailed content of What does eval mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn