How can you make your Python object support slicing?
__getitem__
, but so does slicing!Python's subscript notation ([
...]
) relies on the __getitem__
method.
Here's a class with a __getitem__
method:
...
This is a premium screencast available only to active Python Morsels subscribers.
Feel free to watch some of the free screencasts in the Dunder Methods series.
Need to fill-in gaps in your Python skills? I send weekly emails designed to do just that.