isdisjoint() function in Python
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:
Let set A = {2, 4, 5, 6}
and set B = {7, 8, 9, 10}
set A and set B are said to be be disjoint sets as their
intersection is null. They do-not have any common elements in between them.
Syntax:
set1.isdisjoint(set2)
Parameters:
The isdisjoint() 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.
Return Value:
returns Trueif the two sets are disjoint.
returns Falseif the twos sets are not disjoint.
Below is the Python3 implementation of the above approach:
# 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
Recommended Posts:
- Python - Call function from another function
- Python | dir() function
- Python | oct() function
- Python map() function
- Python | now() function
- Python | hex() function
- Python tell() function
- Help function in Python
- Python | int() function
- id() function in Python
- Python | cmp() function
- Python | How to get function name ?
- sum() function in Python
- ord() function in Python
- round() function in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

