Python Set issuperset()

Python Set x.issuperset(y) method checks if the set x is a superset of y. The method returns True if all the elements of set y are present in set x, else it returns False.

In this tutorial, we will learn the syntax of set.issuperset() method and go through examples covering different scenarios for the arguments that we pass to issuperset() method.

ADVERTISEMENT

Syntax

The syntax of set.issuperset() method is

set.issuperset(other)

where

ParameterDescription
otherA set.

Examples

1. Check if set x is issuperset of y

In the following program, we will take two sets: x, y; such that all the elements of set y are present in set x. x.issuperset(y) must return True.

Python Program

x = {'apple', 'banana', 'cherry', 'mango', 'guava'}
y = {'apple', 'banana'}

if x.issuperset(y) :
    print('x is superset of y.')
else :
    print('x is not superset of y.')
Try Online

Program Output

x is superset of y.
ADVERTISEMENT

2. Set x is not superset of set y

In the following program, we will take two sets: x, y; such that all of the elements of set y are not present in set x. x.issuperset(y) must return False.

Python Program

x = {'apple', 'banana', 'cherry', 'mango'}
y = {'apple', 'guava'}

if x.issuperset(y) :
    print('x is superset of y.')
else :
    print('x is not superset of y.')
Try Online

Program Output

x is not superset of y.

Conclusion

In this Python Tutorial, we learned about Python set method issuperset(). We have gone through the syntax of issuperset() method, and its usage with example programs.