Python Set issubset() Method

Python3 列表Python Sets


Description

The issubset() method is used to determine whether all elements of a set are contained in a specified set. If yes, it returns True; otherwise, it returns False.

Syntax

The syntax of the issubset() method is as follows:

set.issubset(set)

Parameters

  • set -- Required, the set to be compared and searched.

Return Value

Returns a boolean value. If all elements are contained, it returns True; otherwise, it returns False.

Examples

Determine whether all elements of set x are contained in set y:

Example 1

x = {"a", "b", "c"} y = {"f", "e", "d", "c", "b", "a"} z = x.issubset(y) print(z)

The output result is:

True

If not all elements are contained, it returns False:

Example 1

x = {"a", "b", "c"} y = {"f", "e", "d", "c", "b"} z = x.issubset(y) print(z)

The output result is:

False

Python3 列表Python Sets

Other Extensions