When we provide a slice to any sequence object (object that implements __getitem__ and __len__), we get back an instance of the same type with the elements in the slice. Here is how slicing works:
- When we have commas inside
[],__getitem__gets tuple ofsliceobject. - When we have
:inside[],__getitem__gets asliceobject.
slice object has 4 important attributes:
- start
- step
- stop
- indices