17 lines
332 B
Python
17 lines
332 B
Python
# dict.update(other)将另一个字典的键-值对合并到当前字典中(|)
|
|
person_1 = {
|
|
'name':'zhangsan',
|
|
'age':18
|
|
}
|
|
|
|
person_2 = {
|
|
'中文姓名':'张三',
|
|
'年龄':18
|
|
}
|
|
# 第一种方式:
|
|
person_1.update(person_2) # 类似于集合的并集
|
|
print(person_1)
|
|
|
|
# 第二种方式:
|
|
print(person_1 | person_2)
|