#!/usr/bin/python
#coding=utf-8
'''
Created on 2017年11月23日 from home

@author: James zhan
'''

def counter(start_at=0):
count=start_at
while True:
val=(yield count)
print type(val)
print val
if val is not None:

count=val
else:
count+=1
count=counter(5)

print count.next()
print count.next()
print count.next()
count.send(9)
print count.next()

 

执行结果:

5
<type 'NoneType'>
None
6
<type 'NoneType'>
None
7
<type 'int'>
9
<type 'NoneType'>
None
10

posted on 2017-11-23 20:44  jamezhan  阅读(117)  评论(0编辑  收藏  举报