标签:pytho app pen int ems class from enumerate rate
字典的迭代:
#创建字典 dict={‘a‘:1,‘b‘:2,‘c‘:3} #key和value的迭代 for key,value in dict.items(): print(key,‘:‘,value) #key的迭代 for key in dict: print(key) #value的迭代 for value in dict.values(): print(value) #判断对象是否可以迭代 from collections import Iterable isinstance(dict,Iterable)
list 显示下标的迭代:
#创建一个list l=[] for i in range(10): l.append(i) #显示下标的迭代 for i ,value in enumerate(l): print(i,value)
标签:pytho app pen int ems class from enumerate rate
原文地址:https://www.cnblogs.com/cgmcoding/p/13213485.html