Velocity Reviews > the usage of 'yield' keyword

# the usage of 'yield' keyword

Peng Yu
Guest
Posts: n/a

 10-14-2009
http://docs.python.org/reference/sim...ken-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

Paul Rudin
Guest
Posts: n/a

 10-14-2009
Peng Yu <(E-Mail Removed)> writes:

> http://docs.python.org/reference/sim...ken-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

Try the sections on iterators, generators and generator expressions in
the tutorial: <http://docs.python.org/tutorial/classes.html#iterators>

Sean DiZazzo
Guest
Posts: n/a

 10-16-2009
On Oct 13, 6:41*pm, Peng Yu <(E-Mail Removed)> wrote:
> http://docs.python.org/reference/sim...mar-token-yiel...
>
> 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

What do you think about that Peng?!?

Sean DiZazzo
Guest
Posts: n/a

 10-16-2009
On Oct 15, 9:48*pm, Sean DiZazzo <(E-Mail Removed)> wrote:
> On Oct 13, 6:41*pm, Peng Yu <(E-Mail Removed)> wrote:
>
> >http://docs.python.org/reference/sim...mar-token-yiel...

>
> > 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

>
> What do you think about that Peng?!?

Please share your thoughts, as this list is a learning experience for
everyone involved. We can learn from your thoughts/experiences as
well.

Cheers and well being,

~Sean