all Python 3Sets (set)function
frozenset.union
frozenset
Return a new frozenset — the union with the given iterables.
Syntax
f.union(*others)
The | operator wants sets on both sides; union() swallows any iterables, and several of them in one call. The result type comes from the object the method is called on, so frozenset.union(a_set) still yields a frozenset. A frozenset is never updated in place — it has no update(), only a freshly built object.
Examples
print(frozenset({1, 2}).union({3})) # → frozenset({1, 2, 3})
print(sorted(frozenset({1, 2}).union([2, 3], (4,)))) # → [1, 2, 3, 4]
print(sorted(frozenset('ab').union('bc'))) # → ['a', 'b', 'c']
print(frozenset().union()) # → frozenset()
print(type(frozenset({1}).union({2, 3})).__name__) # → frozenset
print(frozenset({1, 2}) | [3]) # → TypeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy