Files
2025PY/day18/06-字典的方法.py
2025-05-22 16:50:44 +08:00

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)