修改
a={'add':"shanghao","name":"zhangdong"} a['name']='zhangsan'
添加
a={'add':"shanghao","name":"zhangdong"} a['
删除
a={"} del a['age'] print a a={'add':"shanghao","name":"zhangdong"}
>>> a={"diqu":"shanghai","name":"xiaolin"} >>> a.clear() >>> a {}
删除了但还是存在
len()测试长度
>>> aname={'name':'xiaowang','sex':'nan','diqu':'shanghai'} >>> len(aname) 3 >>>
keys()
>>> aname={'name':'xiaowang','sex':'nan','diqu':'shanghai'} >>> aname.keys() ['diqu', 'name', 'sex']
values()
>>> aname={'name':'xiaowang','sex':'nan','diqu':'shanghai'} >>> aname.values() ['shanghai', 'xiaowang', 'nan']
has_key(key)如果在字典里返回ture否则返回fales
>>> aname={'name':'xiaowang','sex':'nan','diqu':'shanghai'} >>> aname.has_key('name') True >>> aname.has_key('age') False