# 列表生成器
a = [x for x in range(10)]
print(a)
# 生成器对象的2种定义方法
#1
def add(a):
return a+a
b = (add(x) for x in range(5))
#2 yield
# 生成器的3种访问方法
#1
print(next(g))
#2
for i in g:
print(i)
#3
g.send(None)
g.send('text')
##########1##########
def foo():
print('foo1...')
yield 1
print('foo2...')
yield 2
g = foo()
print(g)
# print(next(g))
# print(next(g))
for i in g:
print(i)
##########2##########
def add(a):
return a+a
b = (add(x) for x in range(5))
print(b)
print(next(b))
print(next(b))
--------------send
def foo():
print('ok1')
count = yield 1
print(count)
print('ok2')
yield 2
g = foo()
#next(g)
g.send(None) # 先执行到yield 1之后
g.send('text') # 从将‘text’赋值给count,再执行到yield 2之后