2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

range

Last updated at Posted at 2020-02-11
for-range.py
"""
これでも0から9をす出力できるが、面倒
list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in list:
    print(i)
"""

# 0 1 2 3 4 5 6 7 8 9が表示される
for i in range(10):
    print(i)

# 2 3 4 5 6 7 8 9が表示される(インデックスが2から始まる)
for i in range(2,10):
    print(i)

# 2 5 8が表示される(インデックスが2から始まり3個飛ばしで9まで表示)
for i in range(2,10,3):
    print(i)

# インデックスの番号を使わないことを明示する場合は_が使われる
for _ in range(10):
    print('hello')
2
4
0

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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?