yield statement : Generator : Buildin Function PYTHON examples


PYTHON examples » Buildin Function » Generator »

 

yield statement


yield statement: defining a generator function,


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


x = gensquares(10)

print x.next()
print x.next()
print x.next()

           
       



Leave a Comment / Note


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


PYTHON examples

 Navioo Buildin Function
» Generator