1
for player in ['勇者', '戦士', '魔法使い']:
print(player)
1の実行結果
勇者
戦士
魔法使い
これにインデックスも一緒に出力したい場合、
indexも
i = 0
for player in ['勇者', '戦士', '魔法使い']:
print(i, player)
i += 1
indexもの実行結果
0 勇者
1 戦士
2 魔法使い
ここでenumerate関数を使えば、
もっと簡単に書ける
enumerate
for i, player in enumerate(['勇者', '戦士', '魔法使い']):
print(i, player)
enumerateの実行結果
0 勇者
1 戦士
2 魔法使い