Chapters
Python114 chapters

ReferenceSet methods

set.intersection()

Only what is in both sets.

Signature

a.intersection(b) or a & b

Parameters

NameMeans
banother set

Returns

A new set.

Example

Python
a = {1, 2, 3}
b = {2, 3, 4}
print(sorted(a & b))

Output

[2, 3]

See also