迭代器
s=['dog','cat']
res=s.__iter__()
print(res.__next__())
print(res.__next__())
迭代器就是_iter_(),
laomuji=('鸡蛋%s'%i for i in range(10))#生成器表达式不需要再调用iter
res=['鸡蛋%s'%i for i in range(10)]#列表解析把【】换掉就是生成器表达式
# # # s=['dog','cat']
# # # res=s.__iter__()
# # # print(res.__next__())
# # # print(res.__next__())
# # #生成器就是函数中有yield而不是return
# # #生成器
# # def test():
# # yield 1
# # yield 2
# # yield 3
# # g=test()
# # print(g)
# # print(g.__next__())
# #三元表达式
# #name='cat'
# name='dog'
# res='you are so clever' if name =='cat' else 'you are so stupy'
# print(res)
#列表解析
# egg_list=[]
# for i in range(10):
# egg_list.append('鸡蛋%s'%i)
# print(egg_list)
#
# res=['鸡蛋%s'%i for i in range(10)]#生成列表好用,但是占内存
# print(res)
# res=['鸡蛋%s'%i for i in range(10) if i <5]#只有三元表达式没有四元表达式
# print(res)
# #生成器老母鸡
# laomuji=('鸡蛋%s'%i for i in range(10))#生成器表达式
# print(laomuji)
# print(laomuji.__next__())
# print(laomuji.__next__())
# print(next(laomuji))
#列表求和sum函数
s=[1,2,3,4,5]
print(sum(s))
print(sum( i for i in range(6) ))#0-5