Possible Duplicate:
“Least Astonishment” in Python: The Mutable Default Argument
I am confused with the following. I have a base class:
class MyBase:
def __init__(self, store=set()):
self._store = store
Now child classes inherit MyBase
class Child1(MyBase):
pass
class Child2(MyBase)
pass
Then,
child1 = Child1()
child2 = Child2()
print(id(child1._store) = id(child2._store))
>>> True
Why do these instances have a shared _store??
I would really appreciate if you could help me out.
Regards, Nav