The issuperset() function in Python is a method used to check if a set is a superset of another set. It returns True if the set contains all elements of another set, otherwise it returns False.
Parameter Values
| Parameter | Description |
|---|---|
| other | A |
Return Values
issuperset() returns a boolean value: True or False.
How to Use issuperset() in Python
Example 1:
The issuperset() method returns True if a set is a superset of another set, otherwise it returns False.
set1 = {1, 2, 3, 4}
set2 = {2, 3}
print(set1.issuperset(set2)) # Output: True
print(set2.issuperset(set1)) # Output: False
Example 2:
If the set is compared with itself using issuperset(), it always returns True.
set1 = {1, 2, 3}
print(set1.issuperset(set1)) # Output: True
Example 3:
The issuperset() method can also be used with frozen sets.
frozenset1 = frozenset([1, 2, 3])
set1 = {1, 2}
print(frozenset1.issuperset(set1)) # Output: True