在python3.x中需要将以前版本中的next改为:__next__
def simpleGen():
yield 1
yield '2 --> punch!'
myG = simpleGen()
for eachItem in myG:
print(eachItem)
运行结果:
1
2 --> punch!
在python3.x中需要将以前版本中的next改为:__next__
def simpleGen():
yield 1
yield '2 --> punch!'
myG = simpleGen()
for eachItem in myG:
print(eachItem)
运行结果:
1
2 --> punch!