Write a Python program to Check if a set a subset of another set


In this program, two sets "a" and "b" are defined. The first set "a" contains elements 4 and 5, while the second set "b" contains elements 1, 2, 3, 4 and 5. The program then checks if "a" is a subset of "b" using the issubset() method. This method returns True if all the elements of set "a" are present in set "b". In this case, the result will be True. Next, the program checks if "b" is a subset of "a" using the issubset() method. This method returns True if all the elements of set "b" are present in set "a". In this case, the result will be False since set "b" contains additional elements (1, 2, and 3) not present in set "a".

Source Code

a = {4,5}
b = {1,2,3,4,5}
print("A Subset of B :",a.issubset(b))
print("B Subset of A :",b.issubset(a))

Output

A Subset of B : True
B Subset of A : False