- 1

How do I use exec() inside a function.

Example: def fun(): exec('x = 20') return x print(fun()) This function when executed gives error that x is not defined.

29th Jan 2022, 6:30 AM
Muneer S A
Muneer S A - avatar
1 Antwort
+ 5
Muneer S A exec is a very dangerous function. Might I suggest you learn basic code syntax before playing with this function
29th Jan 2022, 6:39 AM
Rik Wittkopp
Rik Wittkopp - avatar