This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nums=[1,2,3] | |
i=iter(nums) #listからiteratorを生成 | |
print(next(i)) #1つずつ取り出す | |
print(next(i)) | |
print(next(i)) | |
print(next(i)) #としだす要素がなくなるとStopIterationというエラーを吐く | |
#generatorで自作iteratorを定義するには、関数を1つ作るだけ! | |
#ただし値を返すのにreturn文ではなくyield文を使う | |
def gen1to3(): |