Return True if the set has no elements in common with other . Sets are disjoint if and only if their intersection is the empty set.
The rule here is ‘no elements in common’, and set() has no elements in common with itself: There are no elements in set() that are also in set(). (Due to the fact that there are no elements in set() at all).
The alternative definition ‘if and only if their intersection is the empty set’ makes it even more explicit that set().isdisjoint(set()) should be True.
issuperset ( other ) set >= other
Test whether every element in other is in the set.
Is every element in set() also in set()? Absolutely: set() has no elements which aren’t also in set(). (And of course every set is its own super- and subset)
Two sets are disjoint if they have no elements in common.
a = set()
b = set()
Are there any elements that are in both a and b? No. Then they are
The superset question is a bit more subtle.
The definition of “superset” used by Python includes equality. (Some
mathematicians define superset to be strict and exclude equality.) So
to Python, a set a is a superset of b if every element of b is in a.
Another way to answer it is to ask, is there any element of b not in
a? No. Then every element must be in a, and so a is a superset of b.
We can do the disjoint and superset tests another way. Sets a and b are
disjoint if both of these are False:
any(el in a for el in b)
any(el in b for el in a)
which they are. We can do the superset test a.issuperset(b) like this: