0
1

Pythonのforループでlistを特定の回数回す方法

Posted at

Pythonのループの書き方

リストの全要素に対して、ループを回すとき。

list = [1,2,3,4,5,6,7]
for num in list:
    print(num)

リストの特定の範囲に対して、ループを回すとき。

list = [1,2,3,4,5,6,7]
for num in list[0:3]:
    print(num)

リストで特定の回数、ループを回すとき。

list = [1,2,3,4,5,6,7]
for num in range(4):
    print(num)
0
1
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
0
1