Python set Method - issuperset()

The issuperset() method in Python is used to check if a set is a superset of another set. It returns True if all the elements of the second set are also present in the first set, and False otherwise.

The syntax for the issuperset() method is as follows:

set1.issuperset(set2)
‮‬Source:www.theitroad.com

Here, set1 is the set that we want to check if it is a superset of set2. The method returns True if all the elements of set2 are also present in set1, and False otherwise.

Example:

# Creating two sets
set1 = {1, 2, 3, 4, 5}
set2 = {1, 2, 3}

# Checking if set1 is a superset of set2
print(set1.issuperset(set2))   # Output: True

# Creating another set
set3 = {4, 5, 6}

# Checking if set1 is a superset of set3
print(set1.issuperset(set3))   # Output: False

In the above example, the issuperset() method is used to check if the set set1 is a superset of set2. Since all the elements of set2 (i.e., 1, 2, and 3) are also present in set1, the method returns True. The method is also used to check if the set set1 is a superset of set3. Since the element 6 is not present in set1, the method returns False.