Python Set issuperset() method



The Python Set issuperset() method is used to determine if a set contains all elements of another set. It returns True if the set calling the method contains every element of the set passed as an argument else False.

This method is crucial for comparing sets and assessing their relationships in terms of inclusion. It disregards the order and repetitions of elements by focusing solely on their presence within the sets.

This method is Employed in various scenarios such as data analysis, database operations and algorithmic tasks it facilitates efficient set comparisons by aiding in decision-making processes and ensuring accurate data handling.

Syntax

Following is the syntax and parameters of Python Set issuperset() method −

set.issuperset(iterable)

Parameter

This method accepts a set or iterable to compare with.

Return value

This method returns boolean values as True or False.

Example 1

Following is the example in which we are checking whether multiple sets are supersets or not with the help of python set issuperset() method −

set1 = {1, 2, 3, 4}
set2 = {2, 4}
set3 = {1, 2}

result = set1.issuperset(set2) and set1.issuperset(set3)
print(result)  # Output: True

Output

True

Example 2

In this example we are checking a set with an iterable i.e. list, whether it is a superset or not.

set1 = {1, 2, 3, 4}
list1 = [2, 4]
result = set1.issuperset(list1)
print(result) 

Output

True

Example 3

The empty set is a superset of each and every set and here in this example we check if the set is a superset of an empty set.

set1 = {1, 2, 3}
empty_set = set()
result = set1.issuperset(empty_set)
print(result)  

Output

True
python_set_methods.htm
Advertisements