yield sample progaram
def myfunc(): yield 'one' yield 'two' yield 'three' yield 12345 print("test myfunc") for s in myfunc(): print(s) print("test myfunc by next") gene = myfunc() print(next(gene)) print(next(gene)) print(next(gene)) def myfunc2(x:int): # 0からxまでの値を2倍して返す for z in range(x): yield z*2 print("test myfunc2") for i in myfunc2(5): print(i) ===== RESTART: C:/python/yieldTest20210224.py === test myfunc one two three 12345 test myfunc by next one two three test myfunc2 0 2 4 6 8 >>>
コメント
コメントを投稿