実行環境
- python 3.7.5
- Windows PowerShell
rangeを用いる
- 昇順
- 降順
- 逆順
range.py
>>> for i in range(0, 6):
... print(i)
...
0
1
2
3
4
5
decreasing.py
>>> for i in range(6, 0, -1):
... print(i)
...
6
5
4
3
2
1
reversed.py
>>> for i in reversed(range(0, 6)):
... print(i)
...
5
4
3
2
1
0
listを用いる
list.py
>>> for i in [3.14, "Hello", (1, 2, 3)]:
... print(i)
...
3.14
Hello
(1, 2, 3)
未分類のもの
- 文字列を扱う1
string.py
>>> for i in "abc":
... print(i)
...
a
b
c
編集途中…(rangeとlistについてもまとめたい…)
参考文献
-
Decreasing for loops in Python impossible?
- サイト名 : stackoverflow (2019/11/17)
-
Pythonのrange関数の使い方
- サイト名 : note.nkmk.me (2019/11/17)
-
Pythonのfor文によるループ処理(range, enumerate, zipなど)
- サイト名 : note.nkmk.me (2019/11/17)
-
shiracamusさんのコメントより引用 ↩