如果集合A的所有元素都存在於另一個作為參數傳遞的集合B中,則issubset()方法返回True,如果不存在所有元素,則返回false。
用法:
A.issubset(B) checks whether A is a subset of B or not. 返回: returns true if A is a subset of B otherwise false.
# Python program to demonstrate working of
# issubset().
A = {4, 1, 3, 5}
B = {6, 0, 4, 1, 5, 0, 3, 5}
# Returns True
print(A.issubset(B))
# Returns False
# B is not subset of A
print(B.issubset(A))
輸出:
True False
# Another Python program to demonstrate working
# of issubset().
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 subset of A
print(B.issubset(A))
# Returns False
print(A.issubset(C))
# Returns True
print(C.issubset(B))
輸出:
True False False True
相關用法
注:本文由純淨天空篩選整理自pawan_asipu大神的英文原創作品 issubset() in python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。