Python Function Reference

set.isdisjoint

Check that the set and another collection have no items in common.

Python 3.13
set.isdisjoint(other)

Parameters

otherIterable
The collection to compare with.

Return value

True if there are no common items, otherwise False.

Examples

No common items

Python 3.13
print({1, 2}.isdisjoint({3, 4}))
True

A common item with a list

Python 3.13
print({'a', 'b'}.isdisjoint(['b', 'c']))
False

Details

Unlike the check not (a & b), it does not build a new set and stops at the first common item. An empty set has no common items with any collection.

See also

Where to learn