Python Set – issuperset() Method

It is a method in python that checks if every element of the other set is present in the main set or not. Returns True if the given set is present in the other set (passed in the argument) else returns False. It doesn’t modifies the given set.

Syntax:
set1.issuperset(set2)
set1>=(set2)

Also Read: Python Set – issubset() Method

Example:

# Python code to understand issuperset() method in set
# www.codewindow.in

s1 = {2, 5, 8, 7, 9}
s = {2, 5, 8}
s2 = {2, 8, 9}
s3 = {7, 5}

#is s a superset of s1?
print(s.issuperset(s1))

#is s1 a superset of s?
print(s1.issuperset(s))

#is s3 a superset of s1?
print(s3>=(s1))

#is s2 a superset of s1?
print(s2.issuperset(s1))

Output:

False
True
False
False

Explanation:
Here, all the elements of s1 are not present in set s.
All the elements of s are present in s1.
All the elements of s1 are present not in set s3.
All the elements of s1 are not present in set s2.


Follow Us

You Missed

Also Checkout