舉例1:
a = {
'date': '2022-06-15 14:02:31.345808', 'time': '1655272951346'}
c="aa"
d=2
a.update({
c:d})
print(a)
# {'date': '2022-06-15 14:02:31.345808', 'time': '1655272951346', 'aa': 2}
舉例2:
a = {
'date': '2022-06-15 14:02:31.345808', 'time': '1655272951346'}
a['aa'] = 2
print(a)
# {'date': '2022-06-15 14:02:31.345808', 'time': '1655272951346', 'aa': 2}
舉例3:
a = {
'time': '1655272951346'}
c=["name","address","phone"]
d=["jack","shenzhen","13214564554"]
# 方式一:
for j,k in zip(c,d):
a.update({
j:k})
print(a)
#{'time': '1655272951346', 'name': 'jack', 'address': 'shenzhen', 'phone': '13214564554'}
舉例4:
b = dict(zip(c,d))
print(b)
# {'name': 'jack', 'address': 'shenzhen', 'phone': '13214564554'}
a.update(b)
print(a)
# {'time': '1655272951346', 'name': 'jack', 'address': 'shenzhen', 'phone': '13214564554'}