>>> class List(list):
... def __getitem__(self, i):
... print i, type(i)
... return super(List, self).__getitem__(i)
...
>>> x = List([0,1,2,3])
>>> x[1:3:]
slice(1, 3, None) <type 'slice'>
[1, 2]
>>> x[1:3]
[1, 2]
Why is the second case not using List.__getitem__? What does he use instead?
>>> x[::]
slice(None, None, None) <type 'slice'>
[0, 1, 2, 3]
>>> x[:]
[0, 1, 2, 3]
Repeat the same thing, why the discrepancy here is not these two slicing operations?
source
share