Skip to content
Set Methods

intersection()

Return a new set with elements common to this set and all others.

set.intersection(*others)

set.intersection() returns a new set containing only the elements that exist in the calling set and all provided others iterables.

Equivalent to the bitwise AND operator (set_a & set_b).

Parameters

NameDescription
*othersOne or more iterables to intersect with.

Returns

A new set containing common elements.

Try it

Run it and change it
math_club = {"Alice", "Bob", "Eve"}
science_club = {"Bob", "Charlie", "Eve"}
both = math_club.intersection(science_club)
print(sorted(both))

Worth knowing

  • Multiple intersections: You can pass multiple iterables: set_a.intersection(b, c, d).

Related entries