Can someone please explain what's going on in the following? Why on earth does object b
have the value of object a
's list?
class Test:
def __init__(self, A = []):
self.A = A
def __str__(self):
return str(self.A)
def mutate_A():
a = Test()
a.A.append(1)
return a
def problem_here():
a = mutate_A()
b = Test()
print b # why does this print [1] in python 2.7
problem_here()
Please let me know if I am being unclear or if more information is needed. Thank you.