1. 程式人生 > >python enumerate與range的區別

python enumerate與range的區別

 

for i,city in enumerate(city_list):
    print('%s: %s' %(i+1,city))
# 也可以直接指定開始計數的值
for i,city in enumerate(city_list,7):
    print('%s: %s' %(i,city))

 執行結果:

1: beijing
2: shanghai
3: tianjing
4: wuhan
7: beijing
8: shanghai
9: tianjing
10: wuhan

轉載:https://www.cnblogs.com/tynam/p/8668316.html