I understand why the following happens in python, but it seems kind of counter intuitive. Can anyone provide an explanation of why python should behave like this? Why on the second instantiation of the class G an empty list is not created again?
class G:
def __init__(self, members=[]):
self.members = members
def append(self, x):
self.members.append(x)
a = G()
a.append(1)
a.append(2)
print(a.members) # prints: [1, 2]
b = G()
print(b.members) # prints: [1, 2] <-------- why????
Edit: As mentioned in the comment this issue has been already addressed here.