# Python Set isdisjoint() Method with Example

**Python Set isdisjoint() Method**: Here, we are going to learn check whether there are common elements in two sets or not in Python?

Submitted by **IncludeHelp**, on November 29, 2019

## Set isdisjoint() Method

**isdisjoint() method** is used to check whether elements are common in two sets or not, method is called with one set (commonly known as this set) and another set is supplied as an argument, method returns "True" if none of the elements are common in both sets, else it returns "False".

**Syntax:**

set1.isdisjoint(set2)

**Parameter(s):**

- set1 – It represents the set1 (this set).
- set2 – It represents the set2 (another set to be compared).

**Return value:**

The return type of this method is <class 'bool'>, it returns a Boolean value (True or False).

**Example 1:**

# Python Set isdisjoint() Method with Example # declaring the sets cars_1 = {"Porsche", "Audi", "Lexus"} cars_2 = {"Porsche", "Mazda", "Lincoln"} cars_3 = {"BMW", "Mazda", "Lincoln"} # isdisjoint() method call result = cars_1.isdisjoint(cars_2) print("cars_1.isdisjoint(cars_2): ", result) result = cars_2.isdisjoint(cars_3) print("cars_2.isdisjoint(cars_3): ", result) result = cars_1.isdisjoint(cars_3) print("cars_1.isdisjoint(cars_3): ", result)

**Output**

cars_1.isdisjoint(cars_2): False cars_2.isdisjoint(cars_3): False cars_1.isdisjoint(cars_3): True

**Example 2:**

# Python Set isdisjoint() Method with Example # declaring the sets x = {"ABC", "PQR", "XYZ"} y = {"ABC", "PQR", "XYZ"} z = {"DEF", "MNO", "UVW"} # isdisjoint() method calls result = x.isdisjoint(y) print("x.isdisjoint(y): ", result) result = y.isdisjoint(z) print("y.isdisjoint(z): ", result) result = z.isdisjoint(x) print("z.isdisjoint(x): ", result) result = x.isdisjoint(z) print("x.isdisjoint(z): ", result) result = y.isdisjoint(x) print("y.isdisjoint(x): ", result)

**Output**

x.isdisjoint(y): False y.isdisjoint(z): True z.isdisjoint(x): True x.isdisjoint(z): True y.isdisjoint(x): False

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.