I do not quite understand the difference between the following two similar codes:
def y(x):
temp=[]
def z(j):
temp.append(j)
z(1)
return temp
calling y(2) returns [1]
def y(x):
temp=[]
def z(j):
temp+=[j]
z(1)
return temp
calling y(2) returns UnboundLocalError: local variable 'temp' referenced before assignment. Why + operator generates the error? Thanks