1. 取键:keys()方法 #spyder bb={'人才/可怕':23,'伏地魔&波特':'army','哈哈哈,人才,回合':'hhh'} for ii in bb.keys(): print(ii) #输出: #人才/可怕 #伏地魔&波特 #哈哈哈,人才,回合 2. 取值:values()方法 for jj in bb.values(): print(jj) #输出 # #army #hhh 3. 取键值对:items()方法 for kk,vv in bb.items(): pr
此程序的目的在于,正确而简单的访问字典的键与值 favorite_languages={ 'jen':['python','c'], 'sarah':['c'], 'edward':['ruby','go'], 'phil':['python','java'], } #古老的方法访问字典中键与值 for element in favorite_languages: print(element +"'s favorite languages are:") print("\t&q