Write a Python program to Check if a set is a subset, using comparison operators


The program demonstrates how to check if one set is a subset of another set in Python. The program defines two sets: a and b. The first set, a, contains the elements 'a' and 'b'. The second set, b, contains the elements 'a', 'b', and 'c'.

The program then checks if a is a subset of b and if b is a subset of a. To check this, the program uses the >= operator. The >= operator returns True if the left set is a subset of the right set, and False otherwise. The program prints the results of these checks: "A Subset of B : False" and "B Subset of A : True". This means that a is not a subset of b but b is a subset of a.

Source Code

a = {'a','b'}
b = {'a','b','c'}
print("A Subset of B :",a <= b)
print("B Subset of A :",b <= a) 

Output

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