30. Problem to check if a set is a superset

In this Python set program, we will check whether the given set is a superset of another set 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.

Superset: If there are two sets A and B, then set A is considered as the superset of B, if all the elements of set B are the elements of set A

Set is a superset:

Steps to solve the program

1. Create two sets using {}.
2. Add some elements in the set.
3. Use issuperset to check whether the first set is a superset of second set.
4. Print the output.

				
					a = {1,2,4,5}
b = {4,1}
print("Original set1: ",a)
print("Original set2: ",b)
print("A is superset of B: ",a.issuperset(b))
				
			

Output :

				
					Original set1:  {1, 2, 4, 5}
Original set2:  {1, 4}
A is superset of B:  True
				
			

Related Articles

find the symmetric difference of two sets using the “^” operator

find the common elements between two sets.

Leave a Comment