Menu Close

Python Set isdisjoint() Method

Python set isdisjoint

In this guide, we will learn all about isdisjoint() method. Python set isdisjoint() method check whether items present in both sets or not.

To understand this example, you should have basic knowledge about sets in python. Click here to learn all about Python set.

Python Set isdisjoint() Method

In Python, isdisjoint() method is a set method that is used to check whether items present in both sets or not.
isdisjoint function returns True if none of the items present in both sets, otherwise return False.

Syntax

The syntax of isdisjoint() method is:-

set1.isdisjoin(set2)

Parameter Value

set1:- Required, The set to be search for equal item.

Return Value

isdisjoint() method return True, if the items present in both sets otherwise return False.

Python set isdisjoint() example

Example 1:

set1 = {'a', 'b', 'c', 'x', 'y', 'z'}
set2 = {'a2', 'b2', 'c2', 'x2', 'y2', 'z2'}
result = set1.isdisjoint(set2)
print(result)

Output will be:- True

Example 2:

set1 = {'a', 'b', 'c', 'x', 'y', 'z'}
set2 = {'a', 'b2', 'c', 'x2', 'y', 'z2'}
result = set1.isdisjoint(set2)
print(result)

Output will be:- False

Conclusion

Here we have learned all about isdisjoint() method to check whether items present in both sets or not.
isdisjoint function in python return only a boolean value ( True or False ). This function will work with python sets because it is a set method. If this article will help you, please comment and share it.

Other set methods


For more information:- Click Here

Python Set intersection_update() Method
Python Set issubset() Method

Related Posts