The below function works fine:
def ex():
for x in a:
print(x)
a=[200]
ex()
But the below throws a "UnboundLocalError: local variable 'a' referenced before assignment" error
def ex():
for x in a:
print(x)
a=0
a=[200]
ex()
Why is this happening?