Jun-14-2021, 12:54 PM
This is my Code:
However,
In my situation, I need to put it in the function.
def test(): exec("a=100") print(a) test()The Traceback i get is this:
Error:Traceback (most recent call last):
File "C:\Users\lab135\Desktop\test.py", line 5, in <module>
test()
File "C:\Users\lab135\Desktop\test.py", line 3, in test
print(a)
NameError: name 'a' is not defined
It does not work.However,
exec("a=100") print(a)It works, why?
In my situation, I need to put it in the function.