- #演示生成器
- #!/usr/local/bin/python2.5
- def genner(n):
- for i in range(n):
- yield i ** 2
- x = genner(5)
- print x.next()
- print x.next()
- print x.next()
- print x.next()
- print x.next()
- #该片段来自于http://www.codesnippet.cn/detail/2204201512377.html
来源: http://www.codesnippet.cn/detail/2204201512377.html