I am struggling to understand why instance C keeps data of instance B, even though I initialized the instance variable var with the default empty list. Why is the default argument "var = []" ignored?.
class A():
def __init__(self, var=[]):
self.var = var
B = A()
B.var.append(3)
C = A()
print(C.var)
The print retuns
[3]
Even stranger is this:
class A():
def __init__(self, var=[2]):
self.var = var
B = A()
B.var.append(3)
C = A()
print(C.var)
prints
[2, 3]
How can the statement self.var = var
append to the list from the front?