Generator Function Example : Generator : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » Generator »

 

Generator Function Example


def gensquares(N)
   for i in range(N)
       yield i ** 2             # Resume here later

for i in gensquares(5):          # Resume the function
    print i, ':',                # Print last yielded value



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Statement
» Generator