0
0

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.

【Python】for文でリスト繰り返し処理

Last updated at Posted at 2021-10-05

Pythonのリスト繰り返し処理は二種類あるので、簡単にメモします。

自分の定義したリストです

db_names = ['MySQL', 'PostgreSQL', 'SQLite', 'MariaDB']

1. for文とin文で繰り返し処理

for db_name in db_names:
    print(db_name)
"""
結果:
MySQL
PostgreSQL
SQLite
MariaDB
"""

2. for文とindexで繰り返し処理

説明: リストの長さは4で、rangeは最後の数字-1までを含めるから、
db_names[0]、db_names[1]、db_names[2]、db_names[3]がアクセスされます。

for i in range(len(db_names)):
    print(db_names[i])

"""
結果:
MySQL
PostgreSQL
SQLite
MariaDB
"""

以上、好きな方を使いましょう。

0
0
4

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?