python生成器表达式和生成器函数

简明示例:

 1 >>> C=(c*3 for c in 'suning')    #生成器表达式
 2 >>> list(C)
 3 ['sss', 'uuu', 'nnn', 'iii', 'nnn', 'ggg']
4 >>> def c3times(): #生成器函数 5 for c in 'suning': 6 yield c*3 7 8 9 >>> list(c3times()) 10 ['sss', 'uuu', 'nnn', 'iii', 'nnn', 'ggg']

 

posted @ 2017-11-16 19:31  xiongjiawei  阅读(97)  评论(0)    收藏  举报