python之enumerate函数:获取列表中每个元素的索引和值

源码举例:

 1 def enumerate_fn():
 2     '''
 3     enumerate函数:获取每个元素的索引和值
 4     :return:打印每个元素的索引和值
 5     '''
 6     list = ['Mike', 'male', '24']
 7     for index, value in enumerate(list):
 8         print("索引:" + str(index), ", 值:" + value)
 9 
10 
11 enumerate_fn()

运行结果:

索引:0 , 值:Mike
索引:1 , 值:male
索引:2 , 值:24

  

原文地址:https://www.cnblogs.com/gongxr/p/7497167.html