#_author:生成器
#date:2019/11/4
def fibo(max):
n, before, after = 0, 0, 1
while n<max:
yield before# 有暂存功能
before,after=after,before+after
n=n+1
p=fibo(5)
print(p)#<generator object fibo at 0x00321F70>
print(next(p))#0
print(next(p))#1
print(next(p))#1
print(next(p))#2
print(next(p))#3
print('----------------')
def bar():
print('ok')
count=yield 1
print(count)
yield 2
g=bar()
ret=g.send(None)#等同于next(g) 第一次send 前如果没有next,只能传一个send(None) ok
print(ret)# 1
ret1=g.send('rrr') # rrr
print(ret1)# 2