×

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

Python Tuple count() Method

Python Tuple count() Method The tuple.count() method in Python returns the number of times a specified value appears in the tuple. Syntax tuple.count(value) Parameter value- This parameter represents the element to search in the tuple Return This...

1 minute read.

Pltpcolor in Python

Python: 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 is said...

3 minutes read.

Python Online Compiler

Compose, Run and Offer Python code internet involving OneCompiler's Python online compiler free of charge. It's one of the hearty, highlight-rich web-based compilers for python language, supporting both the adaptations, which...

3 minutes read.

Python Maurer Rose and Rhodonea Curves

In this tutorial, in Python we will make a Maurer Rose example and Rhodonea Curve example. Before we continue to see what precisely is maurer rose or a rhodonea bend...

10 minutes read.

How to Download Python

How to Download Python Python is the most renowned programming language and developers across the globe are working on projects that are made using Python and its libraries. Here we will...

4 minutes read.

How to create a file in Python?

How to create a file in python? Files provide us a convenient way of storing our information. Once we have our data, the next task is to store it so that...

3 minutes read.

Python Logistic Regression with Sklearn & Scikit

In this article, we'll walk through a tutorial for utilising the Python Sklearn (formerly known as Scikit Learn) package to implement logistic regression. To assist you in remembering the concept,...

18 minutes read.

Python program to find the area of a circle

Python program to find the area of a circle This article will discuss how to find the area of a circle in Python with a given radius. The area of a...

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

Defaultdict in Python

In this tutorial, we will study What is defaultdict in Python We will understand it with the aid of certain examples. Before this, we will have a look at dictionaries...

3 minutes read.

Operator Module In Python

Introduction The operator module is used for performing operations using methods rather than utilizing operators in Python code. The operator module provides several methods for performing the operations.  The operator module contains...

7 minutes read.

Python String encode() method

Python String encode() method The string.encode() method in Python returns an encoded version of the string. The default encoding is the current default string encoding Syntax String.encode([encoding[,errors]]) Parameter Encoding: This parameter represents a String specifying...

2 minutes read.

Python Indentation

Overview The spaces at the start of a code line are known as an indentation in Python programming. Indentation is only used for readability in other programming languages like C, C++,...

8 minutes read.

How to reverse a string in Python

In Python language, we have a few ways to reverse a string. In this article, let us discuss these ways and understand the suitability of these ways in different scenarios...

5 minutes read.

Conditional Statements in python

In this article, we will learn about conditional statements and how to apply conditional statements in Python. A decision-making statement is another name for a conditional statement. Decision-making is an important...

5 minutes read.

How to check data type in python

The data type represents the nature of a variable; it determines what kind of data it can store and what operations can be carried out on it. There are five...

4 minutes read.

Run exec python from PHP

PHP (which is a recursive abbreviation for PHP Hypertext Preprocessor) is one of the most broadly involved web improvement innovations on the planet. PHP code utilized for creating sites and...

4 minutes read.

Read Text files in Python

In Python, there are many ways to read text files. Before going into the detailed structure of reading a text file, let us understand how reading text files takes place...

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

Python String isupper() method

Python String isupper() method The String.isupper() method in Python returns a boolean value ‘true’ if all cased characters in the string are uppercase else for any other value is returns false. Syntax String.isupper() Parameter NA Return This...

2 minutes read.