爲什麼下面的代碼在我添加了幾個項目後返回空?python類像列表一樣行爲
class Con(list):
def __init__(self): pass
def __str__(self):
return ' '.join(self)
def add(self, value)
self.append(value)
i for i in range(10):
Con().add(i)
>>> print Con()
# empty space instead of:
0 1 2 3 4 5 6 7 8 9
還有什麼我必須定義爲我的類表現得像一個列表?
好啊,傻我。謝謝 – Shaokan
...你缺少一個':'在線'def add(self,value)' –