- Intersection of n-sets give the common item from the n-sets.
- set intersection in python is done by two ways, first is by intersection() function and second is by '&' operator.
Syntax-
set1.intersection(set2)
Example
set1 is {1,2,3}
set2 is {2,3,5}
set3 is {2,6,7}
intersection will be {2}because only '2' is common in all the sets.
program-
set1={1,2,3,4,5,6}
set2={9,8,7,6,5,4,3}
set3={4,5,6,"one","two"}
set4={1,2,3,4,5,6,7,8,9,0}
print("Set1 is",set1)
print("Set2 is",set2)
print("Set3 is",set3)
print("Set4 is",set4)
print("Intersection of all set is")
print(set1 & set2 & set3 & set4)
Set1 is {1, 2, 3, 4, 5, 6}
Set2 is {3, 4, 5, 6, 7, 8, 9}
Set3 is {4, 5, 6, 'one', 'two'}
Set4 is {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Intersection of all set is
{4, 5, 6}