A.isdisjoint(other) returns True when A and the other iterable have no elements in common. If they share at least one element, it returns False.
This is closely related to intersection(): two sets are disjoint when their intersection is empty. Compare it with issubset() and issuperset().
A={'x','y','z'}
B={'x','b','c'}
print(A.isdisjoint(B))
Output ( 'x' is the common element among two sets A and B )
False
A={'x','y','z'}
B={'a','b','c'}
print(A.isdisjoint(B))
Output ( There is no common element among two sets A and B )
True
A={'x','y','z'}
B='Alex'
print(A.isdisjoint(B))
Output ( here x is the common element )
False
A={'x','y','z'}
B=['a','b','c']
print(A.isdisjoint(B))
Output (No common elements )
True
All Set Methods Subset / Superset / Disjoint Questions with solutions on set
issubset()
issuperset()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.