Python set issubset() Method

A.issubset(B) returns True when every element of A is present in B. The method can test another iterable; for set-to-set comparisons you can also use A <= B.

For the reverse relationship, use issuperset(). To test for no shared elements, use isdisjoint().

Set order: sets are unordered. Whenever an example prints a set, the displayed element order can differ between runs or Python environments.
issubset True
A={'x','y','z','a','b','c'}
B={'x','y','z'}
print(B.issubset(A))
Output ( All elements of B is present in inside A )
True
issubset False
A={'x','y','z','a','b','c'}
B={'x','y','z','k','l','m'}
print(B.issubset(A))
Output ( There are elements in B which are not in A )
False

Using a String

String is an iterable objects
A={'y','t','W','o','e'}
B='Welcome to Python'
print(A.issubset(B))
Output ( here all elements of A is present in B )
True

Using a List

List is an iterable objects
A={'x','y'}
B=['a','b','x','y']
print(A.issubset(B))
Output
True
All Set Methods Subset / Superset / Disjoint Questions with solutions on set isdisjoint() issuperset()


Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer