exec/eval difference | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

exec/eval difference

whats the difference between exec an eval in Python

21st Jan 2018, 9:01 PM
Tim
Tim - avatar
2 Answers
+ 7
The eval function evaluates a Python expression, which yields a value, which is then returned by the function. The exec function takes any Python code and executes it. It doesn't return a value.
22nd Jan 2018, 5:26 AM
Supersebi3
Supersebi3 - avatar
+ 2
correct me if i am wrong eval function takes a string as parameter which contains mathematical operations. example - mathEq = " 5+6*3+8/2" print (eval(mathEq)) and on other side exec function can have python keywords in its parameter string
22nd Jan 2018, 2:18 AM
code learner
code learner - avatar