Thursday, September 25, 2025
HomeLanguagesPython Set issubset() Method

Python Set issubset() Method

Python set issubset() method returns True if all elements of a set A are present in another set B which is passed as an argument, and returns False if all elements are not present in Python.

Python Set issubset() Method Syntax:

Syntax: set_obj.issubset(other_set)

Parameter:

  • other_set: any other set to compare with.

Return: bool

Python set issubset() Method Example:

Python3




s1 = {1, 2, 3, 4, 5}
s2 = {4, 5}
# Output True, since, s2 elements in s1
print(s2.issubset(s1))


Output:

True
Python set issubset() method

Python set issubset() method

Example 1: How Python set issubset() work

Python




A = {4, 1, 3, 5}
B = {6, 0, 4, 1, 5, 0, 3, 5}
  
# Returns True
print(A.issubset(B))
  
# Returns False
# B is not subset of A
print(B.issubset(A))


Output: 

True
False

Example 2: Working with three-set using issubset()

Python




# Another Python program to demonstrate working
# of issubset().
A = {1, 2, 3}
B = {1, 2, 3, 4, 5}
C = {1, 2, 4, 5}
  
# Returns True
print(A.issubset(B))
  
# Returns False
# B is not subset of A
print(B.issubset(A))
  
# Returns False
print(A.issubset(C))
  
# Returns True
print(C.issubset(B))


Output: 

True
False
False
True
RELATED ARTICLES

Most Popular

Dominic
32319 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6680 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6794 POSTS0 COMMENTS
Ted Musemwa
7070 POSTS0 COMMENTS
Thapelo Manthata
6752 POSTS0 COMMENTS
Umr Jansen
6761 POSTS0 COMMENTS