and nowfor something completely implicit--but potentially useful nonetheless in some applicationsit' possible to minimize coding requirements for user-defined iterables by combining the __iter__ method we're exploring here and the yield generator function statement we studied in because generator functions automatically save local variable state and create required iterator methodsthey fit this role welland complement the state retention and other utility we get from classes as reviewrecall that any function that contains yield statement is turned into generator function when calledit returns new generator object with automatic retention of local scope and code positionan automatically created __iter__ method that simply returns itselfand an automatically created __next__ method (next in xthat starts the function or resumes it where it last left offdef gen( )for in range( )yield * gen( __iter__(= true iter(gnext( )next( ( list(gen( )[ create generator with __iter__ and __next__ both methods exist on the same object runs __iter__generator returns itself runs __next__ (next in xiteration contexts automatically run iter and next this is still true even if the generator function with yield happens to be method named __iter__whenever invoked by an iteration context toolsuch method will return new generator object with the requisite __next__ as an added bonusgenerator functions coded as methods in classes have access to saved state in both instance attributes and local scope variables for examplethe following class is equivalent to the initial squares user-defined iterable we coded earlier in squares py file squares_yield py class squares__iter__ yield generator def __init__(selfstartstop)__next__ is automatic/implied self start start self stop stop def __iter__(self)for value in range(self startself stop )yield value * there' no need to alias next to __next__ for compatibility herebecause this method is now automated and implied by the use of yield as beforefor loops and other iteration tools iterate through instances of this class automaticallypython from squares_yield import squares for in squares( )print(iend=' operator overloading