Some libraries, such as numpy, pandas, or even python lists, implement fantastic indexing for their objects. This means that I can do things like:
obj[1:3, :]
If I want to offer this function in my class, I can try to overload the __getitem__ and __setitem__ methods:
class Example(object): def __getitem__(self, x): pass
but I donβt see how this can work, since 1:3 not a valid variable name. How can this functionality be achieved?
source share