Python 3 reference · Set Methods

Python Set isdisjoint() Method

Return True if the set has no elements in common with another iterable.

Python 3 Since 3.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

set.isdisjoint(other)

Parameters

ParameterDescription
other An iterable.

Return value

True or False.

Examples

Any overlap?Try it yourself
print({1, 2}.isdisjoint({3, 4}), {1, 2}.isdisjoint([2, 5]))

Output

True False
Check for forbidden wordsTry it yourself
banned = {"spam", "scam"}
words = "great offer no scam".split()
print("clean" if banned.isdisjoint(words) else "flagged")

Output

flagged

Version history

VersionChange
Python 3.0Added

Was this page helpful?