Home > Article > Backend Development > What does eval mean in python?
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.
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!