enumerate函数是什么?
enumerate:处理可迭代对象,生成:(0,seq[0]),(1,seq[1])...迭代对象
获取索引与值
s = 'this is test' for item in enumerate(s): print(item,end=',')
输出结果:(0, 't'),(1, 'h'),...(11, 't'),
修改:分别使用变量获取索引与值
s = 'this is test' for index,value in enumerate(s): print(index,value,end='|')
结果:0 t|1 h|2 i|3 s|4 |5 i|6 s|7 |8 t|9 e|10 s|11 t|