Program to check if two sets are disjoint sets in Python
In the python, programming article, we are going to learn
-
program to check if two sets are disjoint sets in python
Program to check if two sets are disjoint sets in Python
The program to check if two sets are disjoint sets are as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
names = {"Devjeet","Ajit","Bulbul","Shawriya"}
toppers = {"Ajit","Bulbul","Atul"}
if toppers.isdisjoint(names):
print("The two sets are disjoint sets.")
else:
print("The two sets are not disjoint in nature.")
The output of the program is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
The two sets are not disjoint in nature.
Few important tips about the program
1. The .isdisjoint() method helps us to check if two sets are disjoint or not.
2. If two sets are disjoint, that means they have no common element.
3. The return type of the method is boolean.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Oct 13,2022