English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Méthodes de collection en Python
If all elements of a set exist in another set (passed as a parameter), the issubset() method will return True. Otherwise, it returns False.
A set A is a subset of set B if all elements of set A are in set B.
Here, the set A is a subset of the set B.
The syntax of issubset() is:
A.issubset(B)
The above code checks if A is a subset of B.
issubset() returns
True if A is a subset of B
False if A is not a subset of B
A = {1, 2, 3} B = {1, 2, 3, 4, 5} C = {1, 2, 4, 5} # Returns True print(A.issubset(B)) # Returns False # B is not a subset of A print(B.issubset(A)) # Returns False print(A.issubset(C)) # Returns True print(C.issubset(B))
When running the program, the output is:
True False False True
If you need to check if a set is a superset of another set, you canIn PythonUseissuperset().