import json
dict_a=dict()
dict_b=dict()
dict_a={'a1':'b1','a2':'b2','a3':'b3'}
b={'a4':'b4'}
ks=dict_a.keys()
vs=dict_a.values()
print(ks,type(ks))
print(vs,type(vs))
print(dict_a.items())
#exchange value of a1 and a3
tmp=dict_a['a1']
dict_a['a1']=dict_a['a3']
dict_a['a3']=tmp
print(dict_a)
dict_a.pop('a1')
print(dict_a)
dict_b.update(dict_a)
print(dict_b)
a1=dict_b.get('a1')
print(a1)
dict_b.update({'a1':a1})
print(dict_b)
dict_b.update({'a4':'null'})
print('step 16:',dict_b,type(dict_b))
json_c=json.dumps(dict_b)
print('step 18:',json_c,type(json_c))
dict_c=json.loads(json_c)
print('step 19:',dict_c,type(dict_c))
运行结果
dict_keys(['a1', 'a2', 'a3']) <class 'dict_keys'>
dict_values(['b1', 'b2', 'b3']) <class 'dict_values'>
dict_items([('a1', 'b1'), ('a2', 'b2'), ('a3', 'b3')])
{'a1': 'b3', 'a2': 'b2', 'a3': 'b1'}
{'a2': 'b2', 'a3': 'b1'}
{'a2': 'b2', 'a3': 'b1'}
None
{'a2': 'b2', 'a3': 'b1', 'a1': None}
step 16: {'a2': 'b2', 'a3': 'b1', 'a1': None, 'a4': 'null'} <class 'dict'>
step 18: {"a2": "b2", "a3": "b1", "a1": null, "a4": "null"} <class 'str'>
step 19: {'a2': 'b2', 'a3': 'b1', 'a1': None, 'a4': 'null'} <class 'dict'>