VOOZH about

URL: https://www.geeksforgeeks.org/python/python-set-issubset-method/

⇱ Python Set issubset() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Set issubset() Method

Last Updated : 1 Nov, 2023

Python set issubset() method returns True if all elements of a set A are present in another set B which is passed as an argument, and returns False if all elements are not present in Python.

Python Set issubset() Method Syntax

Syntax: set_obj.issubset(other_set)

Parameter:

  • other_set: any other set to compare with.

Return: bool

Python set issubset() Method Example

This code checks if set s2 is a subset of set s1 and prints True if it is.

Output:

True
👁 Python set issubset() method
Python set issubset() method

How Python set issubset() Work

In this code, it checks whether set A is a subset of set B and then whether set B is a subset of set A. The first print statement returns True because all elements of set A are also in set B. The second print statement returns False because set B contains elements that are not in set A.

Output

True
False

Working with three-set using issubset()

In this code, It checks if one set is a subset of another set using the .issubset() method.

  • A.issubset(B) returns True because all elements in set A are also in set B.
  • B.issubset(A) returns False because set B contains additional elements not in set A.

Output

True
False
False
True
Comment
Article Tags: