Chapters
Python114 chapters

ReferenceSet methods

set.union()

Everything in either set.

Signature

a.union(b) or a | b

Parameters

NameMeans
banother set or iterable

Returns

A new set.

Example

Python
a = {1, 2}
b = {2, 3}
print(sorted(a | b))
print(sorted(a.union([4])))

Output

[1, 2, 3]
[1, 2, 4]

See also