子类化列表,字典和字符串
1. 如果希望实现一个和内建列表行为相似的序列,可以使用子类list
class CounterList(list): def __init__(self, *args): super(CounterList, self).__init__(*args) self.counter = 0 def __getitem__(self, index): self.counter += 1 return super(CounterList, self).__getitem__(index)