#-*-coding:utf-8-*-
import sys
if __name__=="__main__":
dict={"a":"apple","b":"banana","c":"choice"}
print dict
print dict["a"]
dict ["d"]="dog"#向字典添加键值对
print dict
del(dict["c"])#删除
print dict
print dict.pop("b")
print dict
for k in dict:
print "dict[%s]="%k,dict[k]
print dict.keys()
print dict.values()
dict ["f"]="find"
if not dict.has_key("f"):
print "key 'f' not exist"
else:
print dict["f"]
Python字典简单示例
最新推荐文章于 2021-07-27 22:21:37 发布