.issuperset()

Published May 30, 2024
Contribute to Docs

In Python, the .issuperset() method is used to determine if the original set contains all elements of the specified set. It returns True if every element of the specified set is also an element of the original set, and False otherwise.

Syntax

set1.issuperset(set2)
  • set1: The set to be examined to determine if its elements are all present in set2.
  • set2: The set to be checked to see if it contains all elements from set1.

Note: In Python, the >= operator can also be used to check if one set is a superset of another, just like the .issuperset() method.

Example

The following example demonstrates the usage of the .issuperset() method:

set_A = {"pink", "yellow", "red", "blue", "green"}
set_B = {"red", "blue", "green"}
print(set_A.issuperset(set_B))

The above code produces the following output:

True

Codebyte Example

The below codebyte example demonstrates the use of the .issuperset() method:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy