importjson
dict_a={}
dict_b=dict()
# dict_a['a1']='b1'
# dict_a['a2']='b2'
# dict_a['a3']='b3'
dict_a={'a1':'b1','a2':'b2','a3':'b3'}
print(dict_a)
ks=dict_a.keys()
print(ks,type(ks))
vs=dict_a.values()
print(vs,type(vs))
print(dict_a.items())
# dd=dict_a["a1"]
# dict_a['a1']=dict_a['a3']
# dict_a['a3']=dd
dict_a['a1']='b3'
dict_a['a3']='b1'
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['a1']=a1
print(dict_b)
a4=dict_b.get('a4','null')
dict_b['a4']=a4
print(dict_b,type(dict_b))
json_c=json.dumps(dict_b)
print(json_c,type(json_c))
dict_c=json.loads(json_c)
print(dict_c,type(dict_c))
以下為輸出結果:
{'a1': 'b1', 'a2': 'b2', 'a3': 'b3'}dict_keys(['a1', 'a2', 'a3'])dict_values(['b1', 'b2', 'b3'])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}{'a2': 'b2', 'a3': 'b1', 'a1': None, 'a4': 'null'}{"a2": "b2", "a3": "b1", "a1": null, "a4": "null"}{'a2': 'b2', 'a3': 'b1', 'a1': None, 'a4': 'null'}