Easy Tutorial
❮ Python Att Dictionary Keys Python Merging Two Dictionaries ❯

Python Set isdisjoint() Method

Python Set


Description

The isdisjoint() method is used to determine if two sets contain any of the same elements. It returns True if there are no common elements, otherwise it returns False.

Syntax

The syntax for the isdisjoint() method is:

set.isdisjoint(set)

Parameters

Return Value

Returns a Boolean value. It returns True if there are no common elements, otherwise it returns False.

Example

Determine if set y contains any elements from set x:

Example 1

x = {"apple", "banana", "cherry"}
y = {"google", "tutorialpro", "facebook"}

z = x.isdisjoint(y)

print(z)

Output:

True

If there are common elements, it returns False:

Example 2

x = {"apple", "banana", "cherry"}
y = {"google", "tutorialpro", "apple"}

z = x.isdisjoint(y)

print(z)

Output:

False

Python Set

❮ Python Att Dictionary Keys Python Merging Two Dictionaries ❯