I stumbled upon this just now, and i have no idea if this is intended behaviour or a bug. consider the following code:
global a,b;
a=[0,1,2];
b=a;
print("before:",a,b);
def c():
global a,b;
for i in range(3):
a.append(10+i);
c();
print("after:",a,b);
what should happen (at least according to what seems logical to me) is that python only touches the variable a
during the appending process. instead, it decides to the very same thing to b
even though i've never told it to touch b
inside the appending loop. is there some kind of hidden relation to a
and b
i've unknowingly set by making them global, or is this a bug?
sidenotes: replacing global a,b;
with just global a;
inside c() gives me the same output.
i've tried doing the same with the + operator on strings and integers, this seems to be exclusive to the .append function, just a guess though.
I'm running this on Python 3.5.0 x64 on Windows 10