Home >>Python Set Methods >Python Set union() Method
Python set union() method is used to return a set that contains all items from the original given set and all items from the specified sets. You can specify as many sets as you want separated by commas(,).
Syntax:set.union(set1, set2...)
Parameter | Description |
---|---|
set1 | This is a required parameter. It defines the set to unify with. |
set2 | This is an optional parameter. It defines the other set to unify with. |
x = {"Abhi", "Jerry", "Mickey"}
y = {"Wings", "Alpha", "Jerry"}
z = x.union(y)
print(z)
x = {"a", "b", "c"}
y = {"f", "d", "a"}
z = {"c", "d", "e"}
result = x.union(y, z)
print(result)