Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39833
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-02-24 16:39 -0800 |
| Message-ID | <eb6313dd-94f9-406d-b353-3d64d171e0a7@googlegroups.com> (permalink) |
| Subject | yield expression |
| From | Ziliang Chen <zlchen.ken@gmail.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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:39 -0800
Re: yield expression Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-25 00:51 +0000
Re: yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:59 -0800
Re: yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:59 -0800
csiph-web