×

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

How to find square root in python

How to find Square Root of a number In Python Python makes a lot of tasks easier by using different functions, modules, and libraires. There is an inbuilt function in Python...

6 minutes read.

How to comment multiple lines in python?

How to comment multiple lines in python There are two qualities that come up with every good and successful programmer- i) Indenting the code ii) Using comments in the code Let us see how...

4 minutes read.

Python Program to find the length of a string

Python program to find the length of a string A string in Python is a set of Unicode characters. It can't be changed once it's been declared. The number of characters...

2 minutes read.

Iterate a Dictionary in Python – Part 2

In this tutorial, we will learn above various methods used to Iterate a Dictionary in Python. Dictionary: In Python, a dictionary is an unordered collection of data values that is used to...

3 minutes read.

Get Bounding Box Co-ordinates Python

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....

6 minutes read.

Data Distribution in python

Before discussing data distribution, we will discuss each word that is data and Distribution. What is meant by data? A collection of raw facts and figures is called data. The word "raw"...

18 minutes 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.

Python System Requirements

Introduction As we know, Python is a popular programming language usually used to write scripts for operating systems. It’s handy adequate for utilizing in web development and application design. In this article,...

2 minutes read.

Check if the directory exists in Python

To prevent any error, while loading or editing a file, we first have to check that the directory or the file exists or not. This is also done to prevent...

5 minutes read.

Decision Tree in Python

Decision Tree is one of the most essential algorithms in the area of machine learning for classification and regression. But let us first talk about the lifespan of every machine learning...

12 minutes read.

Python Dictionary update() method

Python Dictionary update() method The dictionary.update() method in Python inserts the specified items to the dictionary. Syntax dictionary.update(iterable) Parameter iterable- This parameter represents a dictionary or an iterable object with key value pairs, that will...

1 minute read.

Python variance() function

Variance The variance is the average of the square deviations from the mean. The variance will measure the spread of the dataset from its mean or median value. The greater the...

4 minutes read.

Python K-Means Clustering

K-Means Clustering is a basic yet incredible calculation in information scienceThere are a plenty of true utilizations of K-Means clustering (a couple of which we will cover here)This far reaching...

25 minutes read.

How to run Python code from the command prompt

The Windows operating system's command-line interpreter is CMD or Command Prompt. The "MS-DOS Prompt" is comparable to Command.com, used in DOS and Windows 9x computers. It is similar to Unix...

3 minutes read.

Python coding platform

Python is a popular general-purpose programming language with many applications. High-level data structures, datatypes, dynamic binding, and many other features make it useful for both designing complex applications and "glue...

6 minutes read.

Find Words in String Python

Python : Python programming language is considered a general purpose; it is a high-level programming language that is not much difficult but easier to learn. Python programming language is rich in...

5 minutes read.

How to Pass a list as an Argument in Python

Lists in Python A list is a datatype in python which is used to store the data in a sequence. The lists are mutable; that is, we can change the values...

3 minutes read.

Tensorflow Angular in Python

TensorFlow is an open-source, Python-compatible toolkit for numerical computation that accelerates and simplifies the creation of neural networks and machine learning algorithms. They make the interesting notion that models can be...

6 minutes read.

Python program to find the GCD or HCF

Python program to find the GCD or HCF The largest positive integer that perfectly divides the two numbers is the HCF (Highest Common Factor) or GCD (Greatest Common Deviser). For example,...

5 minutes read.

Iterate through the list in Python

One of the six basic data types of the Python computer language is the list. You must be familiar with the methods and functions that deal with lists in order...

7 minutes read.