iterator pattern gen_ func py def gen_squares( ) while nyield * print("next " + if __name__ ="__main__" gen_squares( print( __next__()print( __next__()print( __next__()print( __next__()print( __next__()the result you get from requesting next is the next squareas you can see here next next next next traceback (most recent call last)file "gen_func py"line in print( __next__()stopiteration there are couple of interesting things you will observe from the outputthe first of which is that every time you call the function the output changes the second thing you should note is that the function starts executing from just below the yield statement and continues until it hits the yield again