What is issuperset() in Python?
The issuperset() method is a set function in Python that tells whether or not a set contains all the elements of another set.
Syntax
set1.issuperset(set2)
Parameter
The issuperset() function takes one parameter. This parameter is the set that is checked to see if all its elements are present in the other set, i.e., whether or not the other (outside) set is its superset.
Return value
The return value is True if the outside set is a superset of the argument set. Otherwise, the function returns False.
Code
In the example below, ‘X’ is the superset of both ‘Y’ and ‘Z’ but not the other way around. This is why the second example returns False.
It is to be noted that if two sets are equal (have all the same elements), they are considered supersets of each other, e.g., set ‘Y’ and ‘Z’ in the code below:
# setsX = {1, 2, 3, 4, 5}Y = {1, 2, 3}Z = {1, 2, 3}# X(superset or not) and Yprint("Is X super set of Y or not?", X.issuperset(Y))# Y(superset or not) and Xprint("Is Y super set of X or not?", Y.issuperset(X))# Z(superset or not) and Yprint("Is Z super set of Y or not?", Z.issuperset(Y))