class Foo:
def __init__(self, stuff = []):
print(stuff)
self.stuff = stuff
def add(self,x):
self.stuff.append(x)
>>>f = Foo()
[]
>>>f.add(1)
>>>g = Foo()
[1]
そして、コードを 1 つだけ変更します (4 行目)。
class Foo:
def __init__(self, stuff = []):
print(stuff)
self.stuff = stuff or []
def add(self,x):
self.stuff.append(x)
>>>f = Foo()
[]
>>>f.add(1)
>>>g = Foo()
[]
4行目で何かを変更しましたが、印刷結果が変更されました(3行目)
それがどのように機能するか知りたいだけです。