Python Set isdisjoint() Method

Determines whether or not two sets have any items in common

Usage

The isdisjoint() method returns True if two sets have no items in common, otherwise FALSE.

Sets are disjoint if and only if their intersection is the empty set.

Syntax

set.isdisjoint(set)

Python set isdisjoint() method parameters
ParameterConditionDescription
setRequiredA set to search for common items in

Examples

# Check if two sets have no items in common
A = {'green', 'blue', 'purple'}
B = {'yellow', 'red', 'orange'}

print(A.isdisjoint(B))
# Prints True
Disjoint set

The method returns FALSE if the specified sets have any item in common.

A = {'red', 'green', 'blue'}
B = {'yellow', 'red', 'orange'}

print(A.isdisjoint(B))
# Prints False