Ref Set Union
# Python3.x Python Set union() Method
[ Python Sets](#)
* * *
## Description
The `union()` method returns the union of two sets, which includes all elements from both sets, with duplicate elements appearing only once.
## Syntax
The syntax for the `union()` method is:
set.union(set1, set2...)
## Parameters
* set1 -- Required, the target set to merge with.
* set2 -- Optional, other sets to merge. Multiple sets can be provided, separated by commas `,`.
## Return Value
Returns a new set.
## Example
Merging two sets, with duplicate elements appearing only once:
## Example 1
x = {"apple", "banana", "cherry"} y = {"google", "tutorial", "apple"} z = x.union(y)print(z)
The output is:
{'cherry', 'tutorial', 'google', 'banana', 'apple'}
Merging multiple sets:
## Example 1
x = {"a", "b", "c"} y = {"f", "d", "a"} z = {"c", "d", "e"} result = x.union(y, z)print(result)
The output is:
{'c', 'd', 'f', 'e', 'b', 'a'}
[ Python Sets](#)
YouTip