dictionary (key-value) (map容器)

#dictionary可以保存不同类型的值
menu = {'fish0':14.50}
list = []
menu['fish1'] = 10.1 # Adding new key-value pair
menu['fish2'] = 12.01
menu[12] = list
list.append(123)     #list中也可以保存不同类型的值
list.append("String")
del menu['fish']    #删除第一个键值对
print ("There are " + str(len(menu)) + " items on the menu.")
print(menu)


#遍历
webster = {
	"Aardvark" : "1",
        "Baa" : "2",
        "Carpet": "3",
        "Dab": "4"
}
for key in webster:
    print(webster[key])

#输出全部键值对
print(list.items())

原文地址:https://www.cnblogs.com/jxgapyw/p/5124473.html