In this Python set program, we will find the intersection between multiple sets with the help of the below-given steps.
What is set?
Sets are used to store multiple items in a single variable.
The set is one of 4 built-in data types in Python used to store collections of data.
It is an unordered collection data type that is iterable, mutable and has no duplicate elements.
Intersection of two sets: The intersection is common elements between the two sets.
Intersection between multiple sets:
Steps to solve the program
1. Create three sets using {}.
2. Add some elements in the set.
3. Use intersection() function to find the intersection of multiple sets.
4. Print the output.
a = {1,2,4,6}
b = {7,8,9,6}
c = {5,8,9,6}
print("Original set1: ",a)
print("Original set2: ",b)
print("Original set3: ",c)
print("Interssection between above sets: ")
print(a.intersection(b.intersection(c)))
Output :
Original set1: {1, 2, 4, 6}
Original set2: {8, 9, 6, 7}
Original set3: {8, 9, 5, 6}
Interssection between above sets:
{6}
Related Articles
Python program to check if any element in a set is a substring of a given string.
Python program to check if any element in a set is a prefix of a given string.
Python program to check if any element in a set is a suffix of a given string.
Python program to find the index of an element in a set.
Python program to convert a set to a dictionary with each element as key and value to an empty set.
Python program to create a set of even numbers from 1 to 20.