+ 2

What is the use of eval () function in python

16th May 2019, 8:41 AM
Mohd Zeeshan Aareef
Mohd Zeeshan Aareef - avatar
3 ответов
+ 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.
16th May 2019, 10:10 AM
Thoq!
Thoq! - avatar
+ 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
16th May 2019, 8:43 AM
Prince PS[Not_Active]
Prince PS[Not_Active] - avatar
+ 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
16th May 2019, 9:01 AM
Melih Melik Sonmez
Melih Melik Sonmez - avatar