def h():
print 'Wen Chuan',
m = yield 5 # Fighting!
print m
d = yield 12
print 'We are together!'
c = h()
m = c.next() #m gets the value of yield 5
d = c.send('Fighting!') #d gets the value of yield 12
print 'We will never forget the date', m, '.', d
请检查上面的代码。它的运行结果如下:
>>> ================================ RESTART ================================
>>>
Wen Chuan Fighting!
We will never forget the date 5 . 12
并且根据我的理解,第一个yield返回值改为“ Fighting
!” 已经,但是为什么稍后print m
它仍然显示值 5?