I am having difficulty to understand how del works in python. Should not del delete the object a after print it's value ?
def f1():
a = 5
def f2():
print('a: ', a)
del a
f2()
print(a)
f1()
By executing this function I am getting error:
UnboundLocalError: local variable 'a' referenced before assignment.
But if I don't delete a then it's working properly.
def f1():
a = 5
def f2():
print('a: ', a)
# del a
f2()
print(a)
f1()
Question:
- is del working at the same time as printing?
- if yes then it should be okay to understand but if not then is there anything I am missing?