.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 within set2.
  • set2: The set being searched for the presence of elements from the set1.

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

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy