











Intersection() in Python
Intersection() in Python
In most probability problems, the concept of the intersection of sets is needed.
The intersection of two given sets is the largest set which contains all the elements that are common to both initial sets.


Syntax :
set1.intersection(set2, set3,…)
Return Type :
Returns a set containing all the common values from the initial sets.
# intersection() method
#example 1
set1 = {‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’ }
set2 = {‘C’, ‘O’, ‘D’, ‘I’, ‘N’, ‘G’ }
print( set1.intersection(set2) )
#example 2
A = { 2, 4, 6, 8 , 10, 12, 14, 16, 18, 20 }
B = { 3, 6, 9, 12, 15, 18, 21, 24, 27, 30 }
C = { 4, 8, 12, 16, 20, 24, 28, 32, 36, 40 }
print( A.intersection(B,C) )
Output : { 'O', 'N' } { 12 }
Login/Signup to comment