+ 8
Exec simply executes the commands you wrote in the sting as if you wrote it directly in the source code Tip: everything in python has a __doc__ string that tells you everything you need to know regarding that thing
24th Jan 2021, 7:46 AM
Angelo
Angelo - avatar
+ 1
No, exec and eval are not the same eval just evaluates an expression and returns the result So you cannot do things like eval("x=1") or eval("if a: print(b)") (statements) On the other hand you cannot use exec for evaluation: exec("a+b") is possible but useless (exec always returns None) but you can do exec("x=a+b")
24th Jan 2021, 11:01 PM
Angelo
Angelo - avatar
0
Angelo exec() is same as eval() ??
24th Jan 2021, 12:52 PM
Ratnapal Shende
Ratnapal Shende - avatar