the usage of 'yield' keyword

Discussion in 'Python' started by Peng Yu, Oct 14, 2009.

  1. Peng Yu

    Peng Yu Guest

    Peng Yu, Oct 14, 2009
    #1
    1. Advertisements

  2. Peng Yu

    Paul Rudin Guest

    Peng Yu <> writes:

    > 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


    Try the sections on iterators, generators and generator expressions in
    the tutorial: <http://docs.python.org/tutorial/classes.html#iterators>
     
    Paul Rudin, Oct 14, 2009
    #2
    1. Advertisements

  3. Peng Yu

    Sean DiZazzo Guest

    On Oct 13, 6:41 pm, Peng Yu <> wrote:
    > http://docs.python.org/reference/simple_stmts.html#grammar-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, Oct 16, 2009
    #3
  4. Peng Yu

    Sean DiZazzo Guest

    On Oct 15, 9:48 pm, Sean DiZazzo <> wrote:
    > On Oct 13, 6:41 pm, Peng Yu <> wrote:
    >
    > >http://docs.python.org/reference/simple_stmts.html#grammar-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
     
    Sean DiZazzo, Oct 16, 2009
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2ZQ==?=

    Static keyword usage in asp.net?

    =?Utf-8?B?RGF2ZQ==?=, Nov 18, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    5,681
    =?Utf-8?B?RGF2ZQ==?=
    Nov 29, 2005
  2. Replies:
    6
    Views:
    763
    Peter Otten
    May 10, 2007
  3. Hamilton, William

    RE: keyword checker - keyword.kwlist

    Hamilton, William, May 10, 2007, in forum: Python
    Replies:
    4
    Views:
    521
  4. Ehsan

    yield keyword usage

    Ehsan, Jul 30, 2007, in forum: Python
    Replies:
    3
    Views:
    1,080
    Steve Holden
    Jul 31, 2007
  5. Replies:
    1
    Views:
    508
    Gabriel Genellina
    Apr 22, 2008
  6. Markus
    Replies:
    1
    Views:
    395
    Mark Hubbart
    Sep 27, 2004
  7. Michael Edgar
    Replies:
    13
    Views:
    484
    Brian Candler
    Apr 21, 2011
  8. VK
    Replies:
    1
    Views:
    202
    Thomas 'PointedEars' Lahn
    Nov 29, 2007
Loading...