python 字典合并

python2:

dict1 = { "name":"owen", "age": 18 }
dict2 = { "birthday": "1999-11-22", "height": 180 }
print(dict(dict1.items() + dict2.items()))

python3:

dict1 = { "name":"owen", "age": 18 }
dict2 = { "birthday": "1999-11-22", "height": 180 }
print(dict(list(dict1.items()) + list(dict2.items())))

你可能感兴趣的:(python 字典合并)