在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!