Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39835 > unrolled thread
| Started by | Ziliang Chen <zlchen.ken@gmail.com> |
|---|---|
| First post | 2013-02-24 16:42 -0800 |
| Last post | 2013-02-24 16:42 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
yield expression Ziliang Chen <zlchen.ken@gmail.com> - 2013-02-24 16:42 -0800
| From | Ziliang Chen <zlchen.ken@gmail.com> |
|---|---|
| Date | 2013-02-24 16:42 -0800 |
| Subject | yield 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
Back to top | Article view | comp.lang.python
csiph-web