Change language

Isdisjoint () function in Python

|

Examples:

 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. 

Syntax :

set1.isdisjoint(set2)

Parameters:

The isdisjoint () method only takes one argument.
It may also require iteration (list, tuple, dictionary and string) to disjunction (). The isdisjoint () method automatically converts the iterables to sets and checks if the sets are disjoint or not.

Returned value:

returns True if the two sets are disjoint.
returns False if the twos sets are not disjoint.

Below is the implementation of the above approach in Python3:

# Python3 program for isdisjoint () function

 

set1 = { 2 , 4 , 5 , 6

 

set2 = { 7 , 8 , 9 , 10 }

set3 = { 1 , 2 }

 

 
# check clause 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 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method