I wrote a code similar to the following and it gives me the local variable 'a' referenced before assignment
error. When I changed that a += [2]
into a.append(2)
, it worked.
def f():
a = [1]
def f1():
a += [2] # => no error with a.append(2)
f1()
print(a)
Why? Why the parser can't recognize the outside a
with +=
?