×

Python Set issubset() method

Python Set issubset() method

The set.issubset() method in Python returns True if all items in the set exists in the specified set, otherwise it returns False.

Syntax

set.issubset(set1)

Parameter

set- This parameter represents the set to check whether it is a subset of set1 or not.

set1- This argument signifies the other set.

Return

This method returns a Boolean value True if all items in the set exists in the specified set, otherwise it returns False.

Example 1

# Python program explaining
# the set.issubset() method
#initializing set1
set1 = {"mango", "banana", "apple", "tomato"}
print("Set 1:",set1)
# initializing set2
set2 = {"mango", "banana"} # subset of set1
print("Set 2:",set2)
# will search whether all the elements of set2 are present in set1 or not 
value= set2.issubset(set1) 
# will return True 
print("Set 2 is a subset of Set 1:",value) 

Output

Set 1: {'mango', 'tomato', 'apple', 'banana'}
Set 2: {'mango', 'banana'}
Set 2 is a subset of Set 1: True 

Example 2

# Python program explaining
# the set.issubset() method
# Initializing set A
A = {"a", "e", "c"} 
# initializing set B 
B = {"a", "b", "c","d", "e"} 
# initializing set C
C = {"a", "b", "d", "e"} 
# Returns True 
print("A is a subset of B: ",A.issubset(B))  
# Returns False 
# As Set B is not subset of Set A 
print("B is a subset of A: ",B.issubset(A)) 
# Returns False  
print("A is a subset of C: ",A.issubset(C)) 
# Returns True 
print("C is a subset of B: ",C.issubset(B)) 

Output

A is a subset of B:  True
B is a subset of A:  False
A is a subset of C:  False
C is a subset of B:  True 

Related Topics

Python next() function

Python next() function The next() function in Python retrieves the next item from the iterator.  Syntax next(iterator[, default]) Parameter iterable: It is a required parameter which represents an iterable object. default: This parameter represents a default value to...

1 minute read.

Python eval() function

Python eval() function The eval() function in Python is used to evaluate the given expression. If the specified expression is a legal Python statement, it will be executed. Syntax eval(expression, globals=None, locals=None) Parameter expression: This parameter represents a String,...

1 minute read.

Accuracy_score Function in Sklearn

A crucial stage in data science is measuring our model's performance using the appropriate metric. In this article, we will examine two methods for calculating the accuracy of your predictions:...

13 minutes read.

Python Selectors

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

4 minutes read.

Python Boolean

In this article, you will learn the boolean variables in python, bool() function in python, and bool operators with examples, Boolean Objects in Python. There are the only two possible values...

6 minutes read.

AX Contour in Python

Python Programming Language Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

3 minutes read.

JWT Decode Python

Python's PyJWT package makes it possible to encrypt and decrypt JSON Web Tokens (JWT). JWT is a public, recognized global benchmark for safely expressing demands between two parties (RFC 7519). JSON...

7 minutes read.

Python List extend() method

Python List extend() method The list.extend() method extends the list by appending all the items from the iterable. Syntax list.extend(iterable) Parameter iterable: It is a required parameter which represents any iterable unlike list, set, tuple, etc. Example 1 # Python...

1 minute read.

Python and its advantages

What is Python? Python is an object-oriented programming language, a general-purpose programming language with a high level, and also an interpreted language that has an easy syntax and dynamic semantics. Python...

7 minutes read.

ModuleNotFoundError No module named 'mysql' in Python

mysql module not found is an error that occurs in python. It appears like ModuleNotError: No module named 'mysql.' This error occurs when you forget to install a module called...

3 minutes read.

Python Unit Test Cheat String

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

Polymorphism in Python

What is polymorphism and why is it important? Polymorphism's literal definition is the state of occurring in diverse shapes or forms. When it comes to programming, the idea of polymorphism is crucial....

3 minutes read.

Python Win32 Process

The Win32 process is essentially a Python procedure. This program provides access to advanced Win32 process creation and management features. Process objects are created through the Create method (the constructor)....

6 minutes read.

Python Dictionary

Dictionary in Python is an unordered collection of data values, which is used to store data values like a map. Unlike different data types that hold just individual assets as...

4 minutes read.

Python hash() function

Python hash() function The hash() function in Python returns the hash value of the object (if it has one).  Syntax hash(object) Parameter obj : This parameter represents the object which we need to convert into hash. Return This...

1 minute read.

How to Print Pattern in Python

How to Print Pattern in Python. Pattern programs are really important for beginners and they are always asked in all the technical interviews. Multiple loops approach is used to print the different...

6 minutes read.

Programs for Printing Pyramid Patterns in Python

<!-- wp:paragraph --><p>Python supports printing patterns using basic for loops. The number of rows is handled by the first outer loop, while the number of columns is handled by the...

9 minutes read.

Python String find() method

Python String find() method The string.find() method in Python finds the first occurrence of the specified value and returns the lowest index in the string if the substring sub is found else it...

2 minutes read.

Composition in Python

Composition in Python Composition is one of the important concepts of Object-oriented programming (OOPs). Composition basically enables us for creating complex types objects by combining other types of objects in the...

6 minutes read.

Managing Multiple Python Versions With pyenv

Introduction If you had ever wished to assist to an application that makes use of several different Python versions but weren't sure whether you would quickly test them all? Do you...

4 minutes read.