











Python Set Intersection()
Intersection() of a Set
The intersection() of two or more sets returns a set that contains all common items from all the sets.
The result set contains a distinct element that is, the item that is present in all sets, the result will contain only one appearance of this item.
∩ the symbol denotes the intersection of sets.


Let us understand this concept with an example, suppose there are two sets A and B, we have to find A ∩ B.
A = { 1 , 2, 3, 4, 5 }
B = { 1, 3, 5, 7, 9 }
A ∩ B = { 1, 3, 5 }
Syntax :
The parameter can be only one or more. You can compare as many sets as you like. Separate each set with a comma.
Return Type :
The intersection() method returns a new set with all the common elements from the set and all other sets (passed as an argument).
If the argument is not passed to the intersection(), it returns a shallow copy of the set.
Using the & operator
Output : {'N', 'O'} {12}
Using intersection() function
Output : {'N', 'O'} {12}
Intersection of three sets
A , B, C are three sets having some elements.
Approach:
- First Calculate intersection of two sets (A ∩ B) and store it in any set say X.
- Then find intersection of X and the third set i.e. (X ∩ C).
A ∩ B ∩ C = (A ∩ B) ∩ C = A ∩ (B ∩ C) = (A ∩ C) ∩ B
Output : A intersectionb B : {18, 12, 6} A intersectionb C : {4, 8, 12, 16, 20} B intersectionb C : {24, 12} (A & B) & C : {12} (A & C) & B : {12} A & (B & C) : {12} A & B & C : {12}
Login/Signup to comment