求大佬帮我看看这个append(0)是什么意思
class CountList(list):def __init__(self, *args):
super().__init__(args)
self.count = []
for i in args:
self.count.append(0)
def __len__(self):
return len(self.count)
def __getitem__(self, key):
self.count += 1
return super().__getitem__(key)
def __setitem__(self, key, value):
self.count += 1
super().__setitem__(key, value)
def __delitem__(self, key):
del self.count
super().__delitem__(key)
def counter(self, key):
return self.count
def append(self, value):
self.count.append(0)
super().append(value)
def pop(self, key=-1):
del self.count
return super().pop(key)
def remove(self, value):
key = super().index(value)
del self.count
super().remove(value)
def insert(self, key, value):
self.count.insert(key, 0)
super().insert(key, value)
def clear(self):
self.count.clear()
super().clear()
def reverse(self):
self.count.reverse()
super().reverse() {:10_277:} 向列表尾部添加0 傻眼貓咪 发表于 2021-10-23 16:28
新手新手,别这样大佬{:5_100:} suchocolate 发表于 2021-10-23 18:11
向列表尾部添加0
为啥会在末尾添加呢,这有什么作用呢大佬,我得意思是这个{:5_92:} 哈哈哈ha1 发表于 2021-10-24 00:37
为啥会在末尾添加呢,这有什么作用呢大佬,我得意思是这个
根据你的代码,得出结果:A = CountList(1, 2, 3, 4, 5)
print(A.count)建议改写成self.count.append(i) 傻眼貓咪 发表于 2021-10-24 08:10
根据你的代码,得出结果:建议改写成
懂了懂了,感谢大佬
页:
[1]