class skipobjectdef __init__(selfwrapped)self wrapped wrapped def __iter__(self)offset while offset len(self wrapped)item self wrapped[offsetoffset + yield item another __iter__ yield generator instance scope retained normally local scope state saved auto this works the same as the non-yield multiscan versionbut with lessand less explicitcodepython from skipper_yield import skipobject skipper skipobject('abcdef' iter(skippernext( )next( )next( ' ' 'efor in skippereach for calls __iter__new auto generator for in skipperprint( yend='aa ac ae ca cc ce ea ec ee of coursethese are all artificial examples that could be replaced with simpler tools like comprehensionsand their code may or may not scale up in kind to more realistic tasks study these alternatives to see how they compare as so often in programmingthe best tool for the job will likely be the best tool for your jobmembership__contains____iter__and __getitem__ the iteration story is even richer than we've seen thus far operator overloading is often layeredclasses may provide specific methodsor more general alternatives used as fallback options for examplecomparisons in python use specific methods such as __lt__ for "less thanif presentor else the general __cmp__ python uses only specific methodsnot __cmp__as discussed later in this boolean tests similarly try specific __bool__ first (to give an explicit true/false result)and if it' absent fall back on the more general __len__ ( nonzero length means trueas we'll also see later in this python works the same but uses the name __nonzero__ instead of __bool__ in the iterations domainclasses can implement the in membership operator as an iterationusing either the __iter__ or __getitem__ methods to support more specific membershipthoughclasses may code __contains__ method--when presentthis operator overloading