1 # 枚举遍历:能够同时将下标及对应的元素遍历出来 2 # 第一个参数为下标,第二个参数为元素 3 #string 4 for i in enumerate("abc"): 5 print(i) 6 for index, ele in enumerate("abc"): 7 print(ele) 8 # list 9 for index, ele in enumerate([1,2,3]): 10 print(ele, index) 11 # tuple 12 for index, ele in enumerate((100,200,300)): 13 print(ele, index) 14 # dict : index:下标 ele:key 15 for index, ele in enumerate({"a":100, "b":200}): 16 print(ele) 17 18 # set 19 for index, ele in enumerate(set((1,2,3,4))): 20 print(index, ele)