set.intersection
Find the items common to the set and all the other collections.
Python 3.13
set.intersection(*others)Parameters
- *othersIterable
- The collections to compare with.
Return value
A new set of common items; the originals are not changed.
Examples
Common items of two sets
Python 3.13
print({1, 2, 3}.intersection({2, 3, 4})){2, 3}Intersection with a list and a tuple
Python 3.13
print({1, 2, 3}.intersection([2, 3, 4], (3, 5))){3}Details
For two sets, the & operator does the same.
