isdisjoint() function in python by R4R Team

- isdisjoint() is a python function which return True or False value.
- It return True if two sets are disjoint to each other i.e. nothing common.
- It return False if two set are not disjoint to each other.

Syntax-

set1.isdisjoint(set2)

Example

set1 is {1,2,3}
set2 is {4,5}
then isdisjoint() will return True

set1 is {1,2,3,4}
set2 is {4,5}
then isdisjoint() will return False


program-

set1={4,5,6}
set2={9,8,7,6,5,4,3}

print("Set1 is",set1)
print("Set2 is",set2)
print(set1.isdisjoint(set2))

set1={1,2,3}
set2={4,5,6}
print("Set1 is",set1)
print("Set2 is",set2)
print(set1.isdisjoint(set2))


output-

Set1 is {4, 5, 6}
Set2 is {3, 4, 5, 6, 7, 8, 9}
False
Set1 is {1, 2, 3}
Set2 is {4, 5, 6}
True


-In this program, initially we have two set {4,5,6} and {9,8,7,6,5,4,3}, here 4,5,6 is common in both the sets that's by it will return False.
- Then we take two sets {1,2,3} and {4,5,6}, here nothing is common that's by it will return True.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!