Expression is a computation that evaluates to a value
To evaluate any expression in python(in my case print(5+10) from above python code), How eval() works different from exec() ?
Answer
How eval() works different from exec() ?
In your two cases, both eval() and exec()do, do the same things. They print the result of the expression. However, they are still both different.
The eval() function can only execute Python expressions, while the exec() function can execute any valid Python code. This can be seen with a few examples:
>>> eval('1 + 2')
3
>>> exec('1 + 2')
>>>
>>> eval('for i in range(1, 11): print(i)')
Traceback (most recent call last):File "<pyshell#45>", line 1, in <module>eval('for i in range(1, 11): print(i)')File "<string>", line 1for i in range(1, 11): print(i)^
SyntaxError: invalid syntax
>>> exec('for i in range(1, 11): print(i)')
1
2
3
4
5
6
7
8
9
10
>>>
Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.Improve…
I want to scrape the product title , product link , product price but when I am using the xpath it is showing the null list . How to add the xpath and for loop to get the above details . I have tried …
This question already has answers here:Closed 11 years ago.Possible Duplicate:Converting a for loop to a while loop I have this for a for loop which I made I was wondering how I would write so it woul…
Given a string, say s=135 and a list, say A=[1,2,3,4,5,6,7], how can I separate the values in the list that are also in s (a digit of s) from the other elements and concatenate these other elements. Th…
I have a bunch of integers which are allocated values using the random module, then converted to letters depending on their position of the alphabet.I then combine a random sample of these variables in…
This question already has answers here:detect key press in python, where each iteration can take more than a couple of seconds?(4 answers)Closed 2 years ago.I was trying to make a while loop which wou…
I want to have my python program generate visio drawings using shapes from a stencil (.vss) file. How can I do that? I think I could generate the xml formatted .vdx file, but there isnt a lot of docum…
I am working on Real Time Object Detection using YOLOv3 with OpenCV and Python. Its works well. Currently I try to capture detected image of object and display in flask. Do someone know how to implemen…
I have to use Tensorflow 0.11 for this code repo and this is the error I get:(py35) E:\opensource_codes\gesture_recognition\hand3d-master>python run.py
Traceback (most recent call last):File "r…