Python Set issuperset() method
Python Set issuperset() method
The set.issuperset() method in Python returns a boolean value True if all items in the specified set exists in the original set, else it returns False.
Syntax
set.issuperset (set1)
Parameter
set- This parameter represents the main set.
set1- This argument signifies the other set to search for equal items.
Return
This method a boolean value True if all items in the specified set exists in the original set, otherwise it returns False.
Example 1
# Python program explaining
# the set.issuperset() method
#initializing set1
set1 = {"mango", "banana", "apple", "tomato"}
print("Set 1:",set1)
# initializing set2
set2 = {"mango", "banana"} # subset of set1
print("Set 2:",set2)
# will search whether the specified set exists in the original set
value= set1.issuperset(set2)
# will return True
print("Set 1 is a super set of Set 2:",value)
Output
Set 1: {'tomato', 'mango', 'banana', 'apple'}
Set 2: {'mango', 'banana'}
Set 1 is a super set of Set 2: True
Example 2
# Python program explaining
# the set.issuperset() method
# Initializing set A
A = {"a", "b", "c","d", "e"}
# initializing set B
B = {"a", "e"}
# initializing set C
C = {"a", "b", "d", "e"}
# will check whether the set A has every elements of another set B
# Returns True
print("A is a super set of B: ",A.issuperset(B))
# will check whether the set B has every elements of another set A
# Returns False
print("B is a super set of A: ",B.issuperset(A))
# will check whether the set A has every elements of another set C
# Returns True
print("A is a super set of C: ",A.issuperset(C))
# will check whether the set C has every elements of another set B
# Returns True
print("C is a subset of B: ",C.issuperset(B))
Output
A is a super set of B: True B is a super set of A: False A is a super set of C: True C is a subset of B: True
Example 3
# Python program explaining
# the set.issuperset() method
#initializing set1
set1 = {"a", "e", "i", "o","u"}
print("Set 1:",set1)
# initializing set2
set2 = {"u", "f","a","w"}
print("Set 2:",set2)
a= set1.issuperset(set2)
if a == True:
{
print("set1 is a superset for set2")}
elif a == False:
{
print("set1 is not a superset for set2")}
Output
Set 1: {'i', 'e', 'a', 'u', 'o'}
Set 2: {'f', 'a', 'u', 'w'}
set1 is not a superset for set2
