python-enumerate() 函數的用法

seasons = ['Spring', 'Summer', 'Fall', 'Winter']
print(list(enumerate(seasons)))
for i,value in enumerate(seasons):
    print(i,value)


輸出結果:
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
0 Spring
1 Summer
2 Fall
3 Winter
相關文章
相關標籤/搜索