39. Problem to find the difference between multiple sets

In this Python set program, we will find the difference 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.

Difference of two sets: The difference between sets A and B is the set of all elements of A that are not elements of B.

Difference between multiple sets:

Steps to solve the program

1. Create three sets using {}.
2. Add some elements in the set.
3. Use the difference() function to find the difference between multiple sets.
4. Print the output.

				
					a = {1,2,4,6}
b = {7,8,9,6}
c = {5,8,9}
print("Original set1: ",a)
print("Original set2: ",b)
print("Original set3: ",c)
print("Difference between above sets: ")
print(a.difference(b.difference(c)))
				
			

Output :

				
					Original set1:  {1, 2, 4, 6}
Original set2:  {8, 9, 6, 7}
Original set3:  {8, 9, 5}
Difference between above sets: 
{1, 2, 4}
				
			

Related Articles

create a frozen set.

find the intersection between multiple sets.

Leave a Comment