这是一个例子。
>>> class MyList(list):
>>> def __sub__(self, other):
>>> L = self[:]
>>> for x in other:
>>> if x in L: L.remove(x)
>>> return L
>>> L = MyList([1, 2, 3, 'spam', 4, 5])
>>> L = L - ['spam']
>>> print L
[1, 2, 3, 4, 5]
当类接受参数时,它需要init,构造函数来获取。但是上面没有init方法。怎么可能?
提前致谢 :)