Python .issubset()
Published May 10, 2024
Contribute to Docs
The .issubset() method checks whether all elements in one set exist within another specified set. It returns True if this condition is met; otherwise, it returns False.
Syntax
set1.issubset(set2)
set1: The set whose elements are being checked for existence withinset2.set2: The set being searched for the presence of elements from theset1.
Example
The following example demonstrates the usage of the .issubset() method:
set_A = {"red", "blue", "green"}set_B = {"pink", "yellow", "red", "blue", "green"}print(set_A.issubset(set_B))
This would print True, because set_B contains all of the elements in set_A. It produces the following output:
True
Codebyte Example
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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