English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced Python knowledge

Python reference manual

Python Set issubset() usage and example

Méthodes de集合 en Python

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

If all elements of B are in A, then the set A is called the superset of set B.

Here, the set A is a superset of the set B, and B is a subset of set A.

The syntax of issubset() is:

A.issuperset(B)

The following syntax code checks if A is a superset of B.

issuperset() return value

issuperset() returns

  • True if A is a superset of B

  • False if A is not a superset of B

Example: How does issubset() work?

A = {1, 2, 3, 4, 5}
B = {1, 2, 3}
C = {1, 2, 3}
# Returns True
print(A.issuperset(B))
# Returns False
print(B.issuperset(A))
# Returns True
print(C.issuperset(B))

When running the program, the output is:

True
False
True

If you need to check if a set is a subset of another set, you canIn PythonUseissubset().

Méthodes de集合 en Python