这是从Learning Python第4版中提取的.它的功能是使用list子类设置.但我不明白第5行list.__init__([]),请帮忙.即使我注释掉这行代码,代码也能正常工作.为什么?
### file: setsubclass.py
class Set(list):
def __init__(self, value = []): # Constructor
list.__init__([]) # Customizes list
self.concat(value) # Copies mutable defaults
def intersect(self, other): # other is any sequence
res = [] # self is the subject
for x in self:
if x in other: # Pick common items
res.append(x)
return Set(res) # Return a new Set
def union(self, other): # other is any sequence
res = Set(self) # Copy me and my list
res.concat(other)
return …Run Code Online (Sandbox Code Playgroud) python ×1