What does eval mean in python?

青灯夜游
Release: 2022-11-28 10:33:18
Original
244913 people have browsed it

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]])
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template