Python set.union() Method
The union() method returns a set containing all items from the
original set, and all items from the specified set(s).
You can specify as many sets you want, separated by commas.
It does not have to be a set, it can be any iterable object.
If an item is present in more than one set, the result will contain only one appearance of this item.
Syntax
set.union(set1, set2...)
Parameters
| Parameter | Description |
|---|---|
set1 |
Required. The set to add items from |
set2... |
Optional. The other sets to add items from, separated by commas |
Return Value
A new set containing the union of sets.
Example
Using the union() method:
Output
Click Run to execute your code
Enjoying these tutorials?