A subset is a type of set that is a part of another set. For example, the earth is a set that contains many elements, and it is also a subset of the solar system.
issubset()
is the set method used to check if a set is a subset of another set or if a whole set is part of another set.
A = {1,2,4}B = {1,2,3,4,5}c = A.issubset(B)if c == True:print('set A is a subset of B')else:print('set A is not a subset of B')
Here, in this example, we take 2 sets called A
and B
.
b
contains all the elements of a
so set a
is called the subset of b
.
we then print the same thing using a print statement.