# 列表
test_list = ['a','b','c','d','e']
for index,test in enumerate(test_list):
print(index,test)
# 0 a
# 1 b
# 2 c
# 3 d
# 4 e
# 字典
test_dic = {'a':'aa','b':'bb'}
for index,test in enumerate(test_dic):
print(index,test)
# 0 a
# 1 b
# 元组
test_set = (('a','aa'),('b','bb'))
for index,test in enumerate(test_set):
print(index,test)
# 0 ('a', 'aa')
# 1 ('b', 'bb')
同样的,enumerate 也可以获取 file 中正在取数据的行数,
参考:https://blog.csdn.net/churximi/article/details/51648388
网友评论