Skip to content
Set Methods

union()

Return a new set with elements from this set and all others.

set.union(*others)

set.union() returns a new set containing all distinct elements from the calling set and all provided others iterables.

Equivalent to the pipe operator (set_a | set_b).

Parameters

NameDescription
*othersOne or more iterables to merge.

Returns

A new set containing all unique elements from all collections.

Try it

Run it and change it
frontend = {"HTML", "CSS", "JavaScript"}
backend = {"Python", "SQL", "JavaScript"}
fullstack = frontend.union(backend)
print(sorted(fullstack))

Worth knowing

  • Multiple iterables: set.union() can combine any number of sets, lists, or generators: a.union(b, c, d).

Related entries