the usage of 'yield' keyword

Peng Yu pengyu.ut at gmail.com
Tue Oct 13 21:41:15 EDT 2009


http://docs.python.org/reference/simple_stmts.html#grammar-token-yield_stmt

The explanation of yield is not clear to me, as I don't know what a
generator is. I see the following example using 'yield'. Could
somebody explain how 'yield' works in this example? Thank you!

def brange(limit):
  i = 0
  while i < limit:
      yield i
      i += 1



More information about the Python-list mailing list