Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39835 > unrolled thread

yield expression

Started byZiliang Chen <zlchen.ken@gmail.com>
First post2013-02-24 16:42 -0800
Last post2013-02-24 16:42 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:42 -0800

#39835 — yield expression

FromZiliang Chen <zlchen.ken@gmail.com>
Date2013-02-24 16:42 -0800
Subjectyield expression
Message-ID<0e43879b-83a4-405c-88a1-dd7f5edd0d75@googlegroups.com>
Hi folks,
When I am trying to understand "yield" expression in Python2.6, I did the following coding. I have difficulty understanding why "val" will be "None" ? What's happening under the hood? It seems to me very time the counter resumes to execute, it will assign "count" to "val", so "val" should NOT be "None" all the time.

Thanks !

code snippet:
----
 def counter(start_at=0):
     count = start_at
     while True:
         val = (yield count)
         if val is not None:
             count = val
         else:
             print 'val is None'
             count += 1

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web