为什么下面的代码在我添加了几个项目后返回空?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)' –