Python .issuperset()

Dashrath_Patel's avatar
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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

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:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours