issubset() function in python by R4R Team

- issubset() is a python function which is applicable only on set data types.
- It compare the two set and check whether one set is subset of another set or not.

Syntax-

set1.issubset(set2)

- It return True if set1 is subset of set2.
- It return False if set1 is not subset of set2.

Example

set1 is {1,2}
set2 is {1,2,3,4}
set1.issubset(set2) will return True.


program-

set1={1,2,3,4}
set2={1,2,3,4,5,6,7,8,9}

print("Set1 is",set1)
print("Set2 is",set2)

print(set1.issubset(set2))
print(set2.issubset(set1))


output-

Set1 is {1, 2, 3, 4}
Set2 is {1, 2, 3, 4, 5, 6, 7, 8, 9}
True
False


-In this program, we have two sets {1,2,3,4} and {1,2,3,4,5,6,7,8,9}, then set1.issubset(set2) will print True value because set1 is subset of set2 but set2 is not a subset of set1 that's by set2.issubset(set1) will print False value.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!