alternativelya user-defined iterable class' method functions can sometimes use yield to transform themselves into generatorswith an automatically created __next__ method-- common application of yield we'll meet in that is both wildly implicit and potentially usefula __getitem__ indexing method is also available as fallback option for iterationthough this is often not as flexible as the __iter__ and __next__ scheme (but has advantages for coding sequencesthe instance objects created from such class are considered iterable and may be used in for loops and all other iteration contexts with classesthoughwe have access to richer logic and data structuring optionssuch as inheritancethat other generator constructs cannot offer by themselves by coding methodsclasses also can make iteration behavior much more explicit than the "magicgenerator objects associated with built-in types and generator functions and expressions (though classes wield some magic of their ownhencethe iterator and generator story won' really be complete until we've seen how it maps to classestoo for nowwe'll have to settle for postponing its conclusion-and its final sequel--until we study class-based iterables in examplegenerating scrambled sequences to demonstrate the power of iteration tools in actionlet' turn to some more complete use case examples in we wrote testing function that scrambled the order of arguments used to test generalized intersection and union functions therei noted that this might be better coded as generator of values now that we've learned how to write generatorsthis serves to illustrate practical application one note up frontbecause they slice and concatenate objectsall the examples in the section (including the permutations at the endwork only on sequences like strings and listnot on arbitrary iterables like filesmapsand other generators that issome of these examples will be generators themselvesproducing values on requestbut they cannot process generators as their inputs generalization for broader categories is left as an open issuethough the code here will suffice unchanged if you wrap nonsequence generators in list calls before passing them in scrambling sequences as coded in we can reorder sequence with slicing and concatenationmoving the front item to the end on each loopslicing instead of indexing the item allows to work for arbitrary sequence typesls [ ]'spamfor in range(len( )) [ : [: print(send='for repeat counts move front item to the end pams amsp mspa spam generator functions and expressions