Home  >  Article  >  Backend Development  >  What does eval mean in python?

What does eval mean in python?

little bottle
little bottleOriginal
2019-05-21 19:20:05134047browse

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]])
  • 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'))

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!

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