We use intersection() method in Python to find the intersection of two or more sets (or any iterable).
The intersection() method returns a set that contains the common items from the original set, and the specified set(s).
Syntax
If there are two sets, set1 and set2, then, intersection of set1, set2 is given as:
set1.intersection(set2)
We can also specify two or more sets,
set1.intersection(set2, set3, set4, ...)
Let’s see one example for more clear understanding,
s1 = {1, 2, 3, 4, 5}
s2 = {3, 5, 7, 9}
print(s1.intersection(s2))
O/P
{3, 5}
Intersection of multiple Sets
s1 = {1, 2, 3, 4, 5}
s2 = {2, 5, 7, 10}
s3 = {1, 7, 6, 5}
print(s1.intersection(s2, s3))
O/P
{5}
In the given three sets, 5 is the only common element.
That’s all here.
