Python Set isdisjoint() Method

Python3 列表Python Sets


Description

The isdisjoint() method is used to determine whether two sets contain the same elements. It returns True if they do not, otherwise it returns False.

Syntax

Syntax of the isdisjoint() method:

set.isdisjoint(set)

Parameters

  • set -- Required, the set to compare with.

Return Value

Returns a boolean value. Returns True if there are no common elements, otherwise returns False.

Example

Determine whether set y contains any elements of set x:

Example 1

x = {"apple", "banana", "cherry"} y = {"google", "example", "facebook"} z = x.isdisjoint(y) print(z)

The output result is:

True

If they contain common elements, it returns False:

Example 1

x = {"apple", "banana", "cherry"} y = {"google", "example", "apple"} z = x.isdisjoint(y) print(z)

The output result is:

False

Python3 列表Python Sets

Other Extensions