+ 4

What is the use of eval function in Python??

27th Mar 2019, 5:11 PM
ANU
ANU - avatar
4 Respostas
+ 10
It's used to evaluate Python expressions but using this to evaluate user input is dangerous because eval('__import__("os").system("rm -rf /")') wil start deleting every file on your computer https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
27th Mar 2019, 6:33 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 3
Ok thanks for ur concern, Pulkit Kamboj, Mert Yazlcl.
27th Mar 2019, 5:38 PM
ANU
ANU - avatar
0
Eval converts a string to normal text print('1*2*3') will print 1*2*3 But, print(eval('1*2*3')) Will be same as print(1*2*3) So, output will be 6.
27th Mar 2019, 5:33 PM
Pulkit Kamboj
Pulkit Kamboj - avatar