Related Articles

# isdisjoint() function in Python

• Difficulty Level : Basic
• Last Updated : 05 Oct, 2021

Python set isdisjoint() function check whether the two sets are disjoint or not, if it is disjoint then it returns True otherwise it will return False. Two sets are said to be disjoint when their intersection is null. In simple words, they do not have any common element in between them.

Examples:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

```Let set A = {2, 4, 5, 6}
and set B = {7, 8, 9, 10} ```

Set A and set B are said to be disjoint sets as their intersection is null. They do not have any common elements in between them.

### Python isdisjoint()  Syntax

set1.isdisjoint(set2)

### Python isdisjoint() Parameters

The isdisjoint() Python method takes only a single argument. It can also take an iterable (list, tuple, dictionary, and string) to disjoint(). The isdisjoint() method will automatically convert iterables to set and checks whether the sets are disjoint or not.

### Python isdisjoint() Return Value

returns Trueif the two sets are disjoint.
returns Falseif the twos sets are not disjoint.

## Python3

 `# Python3 program for isdisjoint() function``set1 ``=` `{``2``, ``4``, ``5``, ``6``}``set2 ``=` `{``7``, ``8``, ``9``, ``10``}``set3 ``=` `{``1``, ``2``}` `# checking of disjoint of two sets``print``(``"set1 and set2 are disjoint?"``,``      ``set1.isdisjoint(set2))` `print``(``"set1 and set3 are disjoint?"``,``      ``set1.isdisjoint(set3))`

Output:

```set1 and set2 are disjoint? True
set1 and set3 are disjoint? False```

## Python3

 `# Set``A ``=` `{``2``, ``4``, ``5``, ``6``}` `# List``lis ``=` `[``1``, ``2``, ``3``, ``4``, ``5``]` `# Dictionary dict, Set is formed on Keys``dict` `=` `{``1``: ``'Apple'``, ``2``: ``'Orage'``}` `# Dictionary dict2``dict2 ``=` `{``'Apple'``: ``1``, ``'Orage'``: ``2``}` `print``(``"Set A and List lis disjoint?"``, A.isdisjoint(lis))``print``(``"Set A and dict are disjoint?"``, A.isdisjoint(``dict``))``print``(``"Set A and dict2 are disjoint?"``, A.isdisjoint(dict2))`

Output:

```Set A and List lis disjoint? False
Set A and dict are disjoint? False
Set A and dict2 are disjoint? True```

My Personal Notes arrow_drop_up