×

Python Set issuperset() method

Python Set issuperset() method

The set.issuperset() method in Python returns a boolean value True if all items in the specified set exists in the original set, else it returns False.

Syntax

set.issuperset (set1)

Parameter

set- This parameter represents the main set.

set1- This argument signifies the other set to search for equal items.

Return

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

Example 1

# Python program explaining
# the set.issuperset() 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 the specified set exists in the original set
value= set1.issuperset(set2) 
# will return True 
print("Set 1 is a super set of Set 2:",value) 

Output

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

Example 2

# Python program explaining
# the set.issuperset() method
# Initializing set A
A = {"a", "b", "c","d", "e"}  
# initializing set B
B = {"a", "e"} 
# initializing set C 
C = {"a", "b", "d", "e"} 
# will check whether the set A has every elements of another set B 
# Returns True  
print("A is a super set of B: ",A.issuperset(B)) 
# will check whether the set B has every elements of another set A
# Returns False 
print("B is a super set of A: ",B.issuperset(A))  
# will check whether the set A has every elements of another set C
# Returns True 
print("A is a super set of C: ",A.issuperset(C)) 
# will check whether the set C has every elements of another set B  
# Returns True 
print("C is a subset of B: ",C.issuperset(B)) 

Output

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

Example 3

# Python program explaining
# the set.issuperset() method
#initializing set1
set1 = {"a", "e", "i", "o","u"}
print("Set 1:",set1) 
# initializing set2
set2 = {"u", "f","a","w"} 
print("Set 2:",set2)
a= set1.issuperset(set2) 
if a == True:
    {
print("set1 is a superset for set2")}
elif a == False: 
     {
print("set1 is not a superset for set2")} 

Output

Set 1: {'i', 'e', 'a', 'u', 'o'}
Set 2: {'f', 'a', 'u', 'w'}
set1 is not a superset for set2 

Related Topics

How to Install Python

Python Installation Guide Step by Step Installing Python is quite simple and easy. In this tutorial, we will show stepwise procedure to install Python and set up the Python environment in different...

2 minutes read.

Add Dictionary to Dictionary in Python

Dictionary in python: Python's execution of a data model, known more commonly as an implicit array, is a dictionary. A dictionary is made up of a group of key-value pairs. Each...

4 minutes read.

SKLearn Clustering

These are ml methods thatare responsible for detecting patterns and the similarities within the data.The clustering methods are unsupervised.Here the data is clustered to form groups with the help of...

3 minutes read.

Python List sort() method

The list.sort () method in Python sorts the items of the list in place. Syntax list.sort(key=None, reverse=False) Parameter reverse: If a Boolean value ‘True’ is passed, the  sorting will be done in the descending order else for ‘False’...

2 minutes read.

Import py file in Python

In Python programming language, a module is a single layer of block of Python code that can be loaded and used by importing into other Python block of code. A module...

4 minutes read.

Python Letter to Number

Python Letter to Number In this tutorial, we will convert the given letters into numbers using a Python. We will convert the given letter into the letter value as defined in...

3 minutes read.

Python Program to Convert Decimal into Binary, Octal, and Hexadecimal

Python Program to Convert Decimal into Binary, Octal, and Hexadecimal We know that the most widely used number system is a decimal system, but the computer only understands binary values. The...

2 minutes read.

Function annotations() in Python

What is Function Annotations? Function annotations provide a way related to different parts of a function at compile time with arbitrary Python expressions. It doesn’t have life in Python runtime execution....

3 minutes read.

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.

How to create a list in Python?

How to create a list in python Python is known for its versatility and its data structures help us to perform different kinds of operations on various datasets irrespective of their...

4 minutes read.

Python MySQL Client

MySQL client is a project that is the subdivision of the MySQLdb package. This package provides an interface that runs the Python database API. Installing mysqlclient You can easily install mysqlclient with...

5 minutes read.

How to run a Python file in CMD

Introduction Today, let us learn about how to run a Python file using cmd. Cmd is nothing but command prompt. So first let us know how to run a Python code...

4 minutes read.

Problem-solving with algorithm and data structures using Python

What is problem-solving? There is no universal method for solving problems. It's frequently a special process that balances your immediate and long-term goals with your available resources. However, several models emphasise...

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

Rank Based Percentile GUI Calculator using PyQt5 in Python

PyQt5: PyQt5 is one of several solutions that Python offers for creating GUI applications. Cross-platform GUI toolkit PyQt5 is a collection of Python interfaces for Qt version 5. With the capabilities...

3 minutes read.

Python hex() function

Python hex() function The hex() function in Python  converts the specified number into a hexadecimal value. Syntax hex(x) Parameter x: The parameter represents an Integer value. Return This function Returns hexadecimal string. Example 1 # Python Program explaining # the hex() function print("The...

1 minute read.

Introducing modern python computing in simple packages

Python is the language for newly evolving technologies and has become one of the most popular computer languages in the world. Python is used in everything right from a simple...

3 minutes read.

How to check version of Python

How to check version of python The versions of Python come with different kinds of features and functionalities. It is not a herculean task to keep track of the updates these...

3 minutes read.

Python MySQL Database Connection

In this article, you will be able to understand how to connect to a MySQL database through Python. We generally can use many methods or modules to connect to the database...

6 minutes read.

Python MySQL Update Operation

Python MySQL Update Operation: In this part of tutorial, we will learn that how can we update a table present in SQL database through our Python program. As like SQL,...

4 minutes read.