Menu Close

Python Set issubset() Method

python set issubset

Python set issubset method is used to check whether all the items of set present in the other set or not. issubset function returns a Boolean value ( True or False ).

Before going through this article, Click here to learn all about Python set.

Python Set issubset() Method

issubset function in python is a pre-defined set function that returns True, if all the items exist in another set otherwise returns False.

Syntax

The syntax of issubset function is:-

set.issubset(set)

Parameter

  • set:- Required. The set to search for equal items.

Set issubset() method example:

Example 1:

num1 = {1, 2, 3, 4, 5, 6, 7}
num2 = {2, 3, 4}
result = num2.issubset(num1)
print(result)

Output will be True because all the items of set num2 present in the num1.

Example 2:

num1 = {1, 2, 3, 4, 5, 6, 7}
num2 = {2, 3, 4, 8, 9, 10}
result = num2.issubset(num1)
print(result)

Output will be False because all the items of set num2 not present in the num1.

Conclusion

So in this tutorial, we have seen all about Python set issubset method to check whether all the items of the set present in another set.

issubset function in Python returns only a boolean value that means True or False. if this article is helpful for you, please share with others who want to learn about sets in python.

Other set methods

For more information:- Click Here

Python Set isdisjoint() Method
Python Set pop() Method

Was this post helpful?

Related Posts

Leave a Reply

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