#生成器函数
def generator():
print(1)
return 'a'
ret = generator()
print(ret)
#只要含有yield关键字的函数都是生成器函数
# yield不能和return共用且需要写在函数内
def generator():
print(1)
yield 'a'
# #生成器函数 : 执行之后会得到一个生成器作为返回值
ret = generator()
print(ret)
print(ret.__next__())
#<generator object generator at 0x0000021E4A067570>
#1
#a
def generator():
print(1)
yield 'a'
print(2)
yield 'b'
yield 'c'
g = generator()
# for i in g:
# print(i)
ret = g.__next__()
print(ret)
ret = g.__next__()
print(ret)
ret = g.__next__()
print(ret)
#娃哈哈%i
def wahaha():
for i in range(200):
yield '娃哈哈%s'%i
g = wahaha()
for i in g:
print(i)
g1 = wahaha()
print('*******',g.__next__())
def wahaha():
for i in range(200):
yield '娃哈哈%s'%i
g = wahaha()
g1 = wahaha()
print(g.__next__())
print(g1.__next__())
#娃哈哈0
#娃哈哈0
l = [1,2,3,4,5]
for i in l:
print(i)
if i == 2:
break
for i in l:
print(i)
def wahaha():
for i in range(200):
yield '娃哈哈%s'%i
g = wahaha()
count = 0
for i in g:
count +=1
print(i)
if count > 50:
break
print('*******',g.__next__())
for i in g:
count +=1
print(i)
if count > 100:
break