Python 3 reference · Set Methods

Python Set intersection() Method

Return a new set with the elements common to this set and all others. The same as a & b.

Python 3 Since 3.0

Syntax

set.intersection(*others)

Parameters

ParameterDescription
*others One or more iterables.

Return value

A new set.

Examples

Common elementsTry it yourself
python = {"Ada", "Bob", "Cy"}
java = {"Bob", "Dee"}
print(python.intersection(java), python & java)

Output

{'Bob'} {'Bob'}
Several sets at onceTry it yourself
a, b, c = {1, 2, 3}, {2, 3, 4}, {3, 4, 5}
print(a.intersection(b, c))

Output

{3}

Version history

VersionChange
Python 3.0Added