Methods and Functions

Python Set issubset()

issubset Python determines whether one set is a subset of another. It returns True if the supplied set exists in the other set (passed in the argument); otherwise, it returns False. It has no bearing on the provided set. Consider the following two sets of numbers: A: 1, 2, 3 and B: 1, 2, 3, 4. We can use the following method to determine if A is a subset of B: Because all of the items in set A are present in set B, this method returns true, indicating that A is a subset of B.

issubset python

Source

Return Value from issubset()

The value of a issubset Python is that of a Boolean expression: this method returns true or false depending on whether the calling set is a subset of the set supplied as a parameter. If the calling set is a subset of the set passed as a parameter, this method returns true; otherwise, it returns false.

Example: How issubset() works?

We have three set numbers in the following example, and we’re using the issubset() method to see if they’re subsets of each other. X is a subset of Y because all of Set X’s elements are present in Set Y, and Z is a subset of Y because all of Set Z’s elements 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: 
X is a subset of Y? True
True X is a subset of Z? False
False Y is a subset of X? False
False Z is a subset of Y? True

Process finished with exit code 0


                

Questions

What is issubset in Python?

Python Set issubset() is a Python method that determines whether a given set is a subset of another. If the supplied set is present in the other set (passed in the argument), it returns True; otherwise, it returns False. It has no effect on the supplied set. 

How do I use Issubset in Python?

This method takes an iterable (list, tuple, dictionary, set, and string) as an argument, and if iterable other than set is supplied, it converts the iterable object to a set object before checking whether all items of a set are also present in a set ( passed as an argument ). If the answer is yes, it will return True; if the answer is no, it will return False.

Syntax : < Set Object >.issubset( <iterable object> ) 

What is a superset in Python?

If a set contains all of the items of another set, the issuperset() method returns True (passed as an argument). If this is not the case, False is returned. If all elements of Y exist in X, it is said that X is the superset of Y.

How do you intersect in Python?

The intersection() method returns a set containing the similarities of two or more sets.

Syntax : set.intersection(set1, set2 … etc)

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

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

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.