Home >>Python Set Methods >Python Set intersection() Method

Python Set intersection() Method

Python Set intersection() Method

Python set intersection() method is used to return a set that contains the similarity between two or more sets.

Syntax:
set.intersection(set1, set2 ... etc)

Parameter Values

Parameter Description
set1 This is a required parameter. It defines the set to search for equal items in.
set2 This is an optional parameter. It defines the other set to search for equal items in.
Here is an example of Python intersection() method:

x = {"Abhi", "Jerry", "Mickey"}
y = {"Wings", "Alpha", "Jerry"}
z = x.intersection(y) 
print(z)

Output:
{'Jerry'}
Example 2:

x = {"a", "b", "c"}
y = {"c", "d", "e"}
z = {"f", "g", "c"}
result = x.intersection(y, z)
print(result)

Output:
{'c'}