本文主要是介绍Python-enumerate索引的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Python中enumerate对于列表、元组和字典的索引,示例程序如下:
"""
Author: Mr. Luo
Date: 2019-10-19
"""
a = (1,2,3,45)
b = [1,2,3,4,5,6,7]
c= {"a":7,"b":8,"c":9}
print("*"*10,"元组索引","*"*10)
for i, ele in enumerate(a):print(i,ele)
print("*"*10,"列表索引","*"*10)
for i, ele in enumerate(b):print(i,ele)
print("*"*10,"字典索引","*"*10)
for i, ele in enumerate(c):print(i,ele)
运行结果:
这篇关于Python-enumerate索引的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!