python47讲课后作业求解答
新手求教,为什么__init__方法里去掉super.__init__会报错IndexError?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_256:} {:5_108:} 看看有大神解决了吗 {:10_254:} 怀疑你们在水贴 kkl44stupid 发表于 2022-7-21 19:10
{:10_256:}
页:
[1]