Python 3 教程
Python 集合
union() 方法返回兩個集合的并集,即包含了所有集合的元素,重復的元素只會出現(xiàn)一次。
union() 方法語法:
set.union(set1, set2...)
返回一個新集合。
合并兩個集合,重復元素只會出現(xiàn)一次:
輸出結(jié)果為:
{'cherry', 'json', 'google', 'banana', 'apple'}
合并多個集合:
{'c', 'd', 'f', 'e', 'b', 'a'}