!!! Python関連ウェブサイト ,リンク,内容 ,[Python.org|https://www.python.org/],公式サイト ,[Pythonドキュメント|https://docs.python.org/ja/],日本語マニュアル !!! 繰り返し !! 無限ループ 無限ループは[while文|https://docs.python.org/ja/3/reference/compound_stmts.html#while]]で実現するのが一般的な模様。 import time while True: print(".", end="", flush=True) time.sleep(1) !! range() インデックスを伴ったループには[range()|https://docs.python.org/ja/3/tutorial/controlflow.html#the-range-function]を使う。 for i in range(5): print(i) for i in range(10, 15): print(i) for i in range(0, -10, -2): print(i) !! enumerate() Rubyの[with_index|https://docs.ruby-lang.org/ja/latest/method/Enumerator/i/with_index.html]相当のことは[enumerate()を使って実現|https://docs.python.org/ja/3/tutorial/datastructures.html#tut-loopidioms]する。 array = ["a", "b", "c"] for i, v in enumerate(array): print(i, v) !!!コメント {{comment}}