the usage of 'yield' keyword

Paul Rudin paul.nospam at
Wed Oct 14 09:42:02 CEST 2009

Peng Yu <pengyu.ut at> writes:

> 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

Try the sections on iterators, generators and generator expressions in
the tutorial: <>

More information about the Python-list mailing list