Answer to the heading, the difference between + and "append" is:
[11, 22] + [33, 44,]
will give you:
[11, 22, 33, 44]
and.
b = [11, 22, 33]
b.append([44, 55, 66])
will give you
[11, 22, 33 [44, 55, 66]]
Answer to the error
This is because when you make an assignment to a variable in a scope, that variable becomes local to that scope and shadows any similarly named variable in the outer scope
The problem here is temp+=[j]
is equal to temp = temp +[j]
. The temp variable is read here before its assigned. This is why it's giving this problem. This is actually covered in python FAQ's.
For further readings, click here. :)