+ 2
What is the use of eval () function in python
3 Antworten
+ 7
https://docs.python.org/3/library/functions.html#eval
It is a builtin-function that evaluates a string (provided that string is a valid expression). So eval(print("234")) would actually print "234" in a program.
You can use it instead of conversion for example. Let us say you don't know the type of a variable you want to convert. Then you can use eval instead of float or int giving you more flexibility.
Try not to use it in combination with input. It might give users the possibility to execute potentially harmful commands.
I am trying to avoid using it at all (eval is evil) but other people may have a different point of view regarding it. I would like to hear about that.
+ 4
Eval function is user to evaluate expressions that are given by the user .
U can use it in the input statement and just evaluate all the expression given by user
Thanks
+ 2
The eval function lets a Python program run Python code within itself.
eval example (interactive shell):
>>> x = 1
>>> eval('x + 1')
2
>>> eval('x')
1