How to Use Set isdisjoint() Method in PythonPython Basics


The isdisjoint() method is used to check if two sets contain the same element or not. It returns True if two sets are disjoint sets, otherwise, it returns False.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

A = {1, 2, 3, 4}
B = {5,6,7,9}
C = {1,11}

print("The isdisjoint between set A and set B is",A.isdisjoint(B))

print("The isdisjoint between set A and set C is",A.isdisjoint(C))

print("The isdisjoint between set C and set B is",B.isdisjoint(C))

Output:

The isdisjoint between set A and set B is True
The isdisjoint between set A and set C is False
The isdisjoint between set C and set B is True

Syntax

set_x.isdisjoint(set_y)

Parameters

The input parameter is the set to be checked.

Return Value

It returns True or false.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us