.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
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours