BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Set issubset() method with examples

Last Updated: April 1, 2019 by Chaitanya Singh | Filed Under: Python Tutorial

The issubset() method in Python checks whether a given Set is a subset of another specified Set. If all the elements of a given Set is present in another Set then the given set is called the subset of another Set.

For example Lets say we have two sets A: {1, 2, 3} & B: {1, 2, 3, 4}, If we want to check whether A is a subset of B then we call this method like this – A.issubset(B), this method would return true because all the elements of set A are present in B which means A is a subset of B.

Python Set issubset() method Syntax

set.issubset(set)

Parameter: This method accepts a Set as a parameter.
Return Value: Boolean value. This method returns true or false based on the comparison, if the calling set is a subset of the set passed as a parameter then this method returns true else it returns false.

Python Set issubset() method Example

In the following example we have three set numbers and we are checking whether they are subset of each other using issubset() method. X is a subset of Y because all the elements of Set X are present in set Y, similarly Z is a subset of Y because all the elements of Set Z are present in Set Y.

# Set X
X = {1, 2, 3}

# Set Y
Y = {1, 2, 3, 4}

# Set Z
Z = {3, 4}

print("X is a subset of Y?", X.issubset(Y))
print("X is a subset of Z?", X.issubset(Z))
print("Y is a subset of X?", Y.issubset(X))
print("Z is a subset of Y?", Z.issubset(Y))

Output:
Python issubset() method example

Top Related Articles:

  1. Python Recursion
  2. Python Data Types
  3. Python Keywords and Identifiers with examples
  4. Python Constructors – default and parameterized
  5. Python all() Function with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap