The issuperset()
method is used to check whether a set is a super set of another set given as argument.
A set is a super set if it contains all the elements of the other set and possibly more. For example, set {1, 2, 3, 4, 5}
is a super set of both, {2, 4}
and {1, 3, 5}
as it contains all the elements of both sets.
Logically, any set its own super set.
set1.issuperset(set2)
copy
set2 |
The set to check whether this set is a super set of. |
The method returns True
if the set is a super set of the given set2
, else False
.
In the above example, the issuperset()
method returns True
in all cases because the integers
set is a super set of all the sets passed as arguments including itself.
In the above snippet, the issuperset()
method returns False in both case.
Using the >=
operator instead
The >=
operator is the equivalent operator version of the superset()
method. It also determines if a set is a super set of another set.
set1 >= set2
copy
It returns True
if set1
is a superset of set2
, else False
.
Check if a set is a strict super set
A strict super set is a set that contains all elements of another set, but there must be at least one more additional element in the super set. It is also known as a proper super set.
A set is not its own strict super set.
To check whether a set s a strict super set, we use the >
operator.
set1 > set2
copy
The operation returns True
if set1
is a strict super set of set2
.