increase:
a={"name":"唐僧","age":18,"sex":"男"} a["name"]="杀神" print(a)
{ 'Name': 'kill God', 'age': 18, 'sex': 'M' #} have a name key-value, direct coverage
a={"name":"唐僧","age":18,"sex":"男"} a["name1"]="杀神" print(a)
{ 'Name': 'monk', 'age': 18, 'sex': 'M', 'name1': 'kill God' #} name1 not this key, keys and values added
delete:
a={"name":"唐僧","age":18,"sex":"男"} a.pop("name") print(a)
{'age': 18, 'sex': '男'}
a={"name":"唐僧","age":18,"sex":"男"} b=a.pop("name1",None) print(b," " ,type(b))
None <class 'NoneType'> # Without this key names being given, the default add None, type type "NoneType", the return value may be added, is shown below:
= {A " name " : " Tang " , " Age " : 18 is, " Sex " : " M " } B = a.pop ( " NAME1 " , " no such key " ) Print (B, " " , type (b))
Without this key <class 'str'>
a.clear () # Empty dictionary
del a # remove the entire dictionary
change:
a={"name":"唐僧","age":18,"sex":"男"}
c={"name":"孙悟空","age":500,"sex":"男","wuqi":"嘴"}
a.update(c)
print(a)
print(c)
{ 'name': 'Monkey', 'age': 500, 'sex': ' M', 'wuqi': 'mouth'}
{ 'name': 'Monkey', 'age': 500, 'sex': 'M', 'wuqi': 'mouth'}
C # in the key and value in updating to a, c and some key-value pairs, a no, then add keys and values.
a={"name":"唐僧","age":18,"sex":"男","职业":"和尚"} c={"name":"孙悟空","age":500,"sex":"男","wuqi""Mouth":} a.update(c) print(a) print(c)
{ 'name': 'Monkey', 'age': 500, 'sex': ' M', 'occupation': 'Monk', 'Wuqi': 'mouth'}
{ 'name': 'Monkey', 'Age ': 500,' sex ': ' M ',' wuqi ':' mouth '}
#a some key-value pairs, c not, then save.