代码点读机 / Python / union

union Python · 集合方法

返回两个集合合并后的新集合。

怎么用

集合.union(另一个集合)

小例子

print({1, 2}.union({2, 3}))

运行结果

{1, 2, 3}

官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html#set

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条