**
生成器表达方式:1.生成器函数 2.生成器表达式
**
1.生成器函数
def test():
yield 1
yield 2
yield 3
g= test()
print(g)
print(g.__next__())
print(g.__next__())
2.生成器函数
2.1三元表达式
name= 'alex'
res='SB' if name == 'alex' else '帅哥'
2.2列表解析
2.2.1
egg_list=[]
for i in range(10):
egg_list.append('鸡蛋%s'%i)
print(egg_list)
l = ['鸡蛋%s' % i for i in range(10)]
l1 = ['鸡蛋%s' % i for i in range(10) if i > 3]
print(l)
print(l1)
2.2.2生成器表达式
laomuji= ('鸡蛋%s'%i for i in range(10))#生成器表达式
print(laomuji)
print(laomuji.__next__())
print(laomuji.__next__())
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))
print(next(laomuji))