更新示例:
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.update(y)
print(x){“微软”、“樱桃”、“香蕉”、“谷歌”、“苹果”}
联合示例:
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.union(y)
print(z){“谷歌”、“樱桃”、“苹果”、“微软”、“香蕉”}
update和union方法的区别在于是否发生内部更新。这类似于例如-交集对intersection_update.
更新应该被命名为union_update吗?
发布于 2021-05-31 13:36:45
它非常类似于union()方法,不同之处在于,其中union()方法创建并返回一个新的集合,其中包含所有可迭代性中存在的所有元素(不同),update()方法用所有可迭代的所有不同元素更新调用该方法的集合。
请访问此站点以获得更多了解,https://codedestine.com/python-set-union-example/
发布于 2021-05-31 13:46:23
不,Union和Update都是不同的,它没有被重命名。你想达到什么目的?
https://stackoverflow.com/questions/67774789
复制相似问题