0
1

More than 3 years have passed since last update.

pythonのfor文でリストの要素とインデックス同時に取り出す方法(enumerate関数)

Last updated at Posted at 2020-07-23

普通(?)だったら

list = ['a','b','c','d']
for i in range(len(list)):
    print(i,list[i])

と書くが
enumerate関数を使うと

list = ['a','b','c','d']
for index,value in enumerate(list):
    print(index,value)

と書ける.

実行結果
0 a
1 b
2 c
3 d

参考文献

現場で使える! Python深層学習入門 Pythonの基本から深層学習の実践手法まで

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