The issuperset()
method is used to check if a set is a superset of another set. A set is considered a superset of another set if it contains all the elements of the other set.
issuperset()
method:
result = set1.issuperset(set2)
Parameters:
set1
: The set you want to check if it is a superset.set2
: The set you want to check against for being a subset.
# Creating two sets
set1 = {1, 2, 3, 4, 5}
set2 = {1, 2}
# Checking if set1 is a superset of set2
result = set1.issuperset(set2)
print(result) # Output: True (set1 is a superset of set2)
In this example, the issuperset()
method is applied to set1
and set2
. Since set1
contains all the elements of set2
(1 and 2), the result is True
, indicating that set1
is a superset of set2
.
Let's see another example where set1
is not a superset of set2
:
# Creating two sets
set1 = {1, 2, 3, 4, 5}
set2 = {1, 2, 6}
# Checking if set1 is a superset of set2
result = set1.issuperset(set2)
print(result) # Output: False (set1 is not a superset of set2)
In this case, set1
does not contain all the elements of set2
, as it is missing element 6. Therefore, the issuperset()
method returns False
, indicating that set1
is not a superset of set2
.