def gensquares(N): for i in range(N): yield i ** 2 # Resume here laterfor i in gensquares(5): # Resume the function print i, ':', # Print last yielded value