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

What does eval mean in python?

little bottle
Release: 2020-09-17 13:27:49
Original
134292 people have browsed it

eval is a built-in function of Python. The function of this function is to return the result of the expression passed in the string. That is, when assigning a variable, the representation on the right side of the equal sign is written in string format, and the return value is the result of this expression.

What does eval mean in python?

eval()The function evaluates the string str as a valid expression and returns the calculation result. It is very useful when combined with math as a calculator.

Syntax:

eval(expression[, globals[, locals]])
Copy after login
  • 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.

Other usage:

Can convert list, tuple, dict and string into each other.

Give a chestnut:

print(eval('1+2'))
Copy after login

Output result: 3

Related learning recommendations: python video

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template