slice assignments--in (and usually in xit receives slice object for the latterwhich may be passed along in another index assignment or used directly in the same wayclass indexsetterdef __setitem__(selfindexvalue)self data[indexvalue intercept index or slice assignment assign index or slice in fact__getitem__ may be called automatically in even more contexts than indexing and slicing--it' also an iteration fallback optionas we'll see in moment firstthoughlet' take quick look at ' flavor of these operations for readersand clarify potential point of confusion in this category slicing and indexing in python in python onlyclasses can also define __getslice__ and __setslice__ methods to intercept slice fetches and assignments specifically if definedthese methods are passed the bounds of the slice expressionand are preferred over __getitem__ and __seti tem__ for two-limit slices in all other casesthoughthis context works the same as in xfor examplea slice object is still created and passed to __getitem__ if no __get slice__ is found or three-limit extended slice form is usedc:\codec:\python \python class slicerdef __getitem__(selfindex)print index def __getslice__(selfij)print ij def __setslice__(selfij,seq)print ij,seq slicer()[ slicer()[ : slicer()[ : : slice( runs __getitem__ with intlike runs __getslice__ if presentelse __getitem__ runs __getitem__ with slice()like xthese slice-specific methods are removed in xso even in you should generally use __getitem__ and __setitem__ instead and allow for both indexes and slice objects as arguments--both for forward compatibilityand to avoid having to handle twoand three-limit slices differently in most classesthis works without any special codebecause indexing methods can manually pass along the slice object in the square brackets of another index expressionas in the prior section' example see the section "membership__contains____iter__and __getitem__on page for another example of slice interception at work indexing and slicing__getitem__ and __setitem__