0
0

More than 3 years have passed since last update.

pythonでfor文の例文を集める

Last updated at Posted at 2019-11-17

実行環境

  • 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についてもまとめたい…)

参考文献


  1. shiracamusさんのコメントより引用 

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0