expect generator functionsyield versus return in this part of the bookwe've learned about coding normal functions that receive input parameters and send back single result immediately it is also possiblehoweverto write functions that may send back value and later be resumedpicking up where they left off such functionsavailable in both python and xare known as generator functions because they generate sequence of values over time generator functions are like normal functions in most respectsand in fact are coded with normal def statements howeverwhen createdthey are compiled specially into an object that supports the iteration protocol and when calledthey don' return resultthey return result generator that can appear in any iteration context we studied iterables in and figure - gave formal and graphic summary of their operation herewe'll revisit them to see how they relate to generators state suspension unlike normal functions that return value and exitgenerator functions automatically suspend and resume their execution and state around the point of value generation because of thatthey are often useful alternative to both computing an entire series of values up front and manually saving and restoring state in classes the state that generator functions retain when they are suspended includes both their code locationand their entire local scope hencetheir local variables retain information between resultsand make it available when the functions are resumed the chief code difference between generator and normal functions is that generator yields valuerather than returning one--the yield statement suspends the function and sends value back to the callerbut retains enough state to enable the function to resume from where it left off when resumedthe function continues execution immediately after the last yield run from the function' perspectivethis allows its code to produce series of values over timerather than computing them all at once and sending them back in something like list iteration protocol integration to truly understand generator functionsyou need to know that they are closely bound up with the notion of the iteration protocol in python as we've seeniterator objects define __next__ method (next in )which either returns the next item in the iterationor raises the special stopiteration exception to end the iteration an iterable object' iterator is fetched initially with the iter built-in functionthough this step is no-op for objects that are their own iterator comprehensions and generations