LoginSignup
0
3

More than 1 year has passed since last update.

enumerate

Last updated at Posted at 2021-07-05

enumerate関数

enumerateはリストの要素と添字を取り出すことができる。
繰り返し文などで使う。

for 変数1、変数2 in enumerate(リスト名):
変数1には1添字、変数2には要素が入る。

sample_list = ['アメリカ','イギリス','中国','日本']

for num,name in enumerate(sample_list):
  print(str(num) + name)

実行結果

0アメリカ
1イギリス
2中国
3日本
0
3
1

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
3