on related notedon' confuse the (perhaps unfortunately named__index__ method in python for index interception--this method returns an integer value for an instance when needed and is used by built-ins that convert to digit strings (and in retrospectmight have been better named __asindex__)class cdef __index__(self)return (hex( ' xffbin( ' oct( ' integer value although this method does not intercept instance indexing like __getitem__it is also used in contexts that require an integer--including indexing(' )[ ' (' )[ ' (' )[ :'cas index (not [ ]as index (not [ :]this method works the same way in python xexcept that it is not called for the hex and oct built-in functionsuse __hex__ and __oct__ in (onlyinstead to intercept these calls index iteration__getitem__ here' hook that isn' always obvious to beginnersbut turns out to be surprisingly useful in the absence of more-specific iteration methods we'll get to in the next sectionthe for statement works by repeatedly indexing sequence from zero to higher indexesuntil an out-of-bounds indexerror exception is detected because of that__geti tem__ also turns out to be one way to overload iteration in python--if this method is definedfor loops call the class' __getitem__ each time throughwith successively higher offsets it' case of "code oneget one free"--any built-in or user-defined object that responds to indexing also responds to for loop iterationclass stepperindexdef __getitem__(selfi)return self data[ix stepperindex( data "spam operator overloading is stepperindex object