Python 集合 update() 方法
例
将y
中的项插入 x
集合:
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.update(y)
print(x)
运行示例»定义和用法
update()
方法通过添加另一个集合中的项目来更新当前集合。
如果两个集合中都存在项目,则更新集合中只会出现此项目的一个。
语法
set.update(set)
参数值
参数 | 描述 |
---|---|
set | 必须项。要插入的集合 |