繰り返しループのforを使ったPythonサンプルコードを以下に記します。
htmlinsert(): The given local file does not exist or is not readable.
$ python --version Python 2.7.3
$ lsb_release -d Description: Ubuntu 12.04.4 LTS
以下の繰り返しループ構文のforを使ったPythonサンプルコードと実行結果を記します。
リスト内に格納されている各種項目分forループする場合
l = [1, "hello", 2, "world"] for i in l: print i
$ python for1.py 1 hello 2 world
range関数を使ってスタート値とエンド値を指定してループしています。
start = 1 end = 10 for i in range(start, end + 1): print i上記のサンプルコードでは、開始値1で終了値を10としています。
$ python for2.py 1 2 3 4 5 6 7 8 9 10
start = 1 end = 10 step = 3 for i in range(start, end + 1, step): print i上記のサンプルコードでは、開始値1で終了値を10としています。
$ python for3.py 1 4 7 10
以上、Pythonによるforループのサンプルコードでした。
htmlinsert(): The given local file does not exist or is not readable.