如果集合A的所有元素都占用作為參數傳遞的集合B,則issuperset()方法返回True,如果集合A中的所有元素都不存在,則返回false。
這意味著如果A是B的超集,則它返回true;否則,它返回true。否則錯
用法:
A.issuperset(B)
checks whether A is a superset of B or not.
返回值:
True if A is a superset of B; otherwise false.
代碼1:
# Python program to demonstrate working of
# issuperset().
A = {4, 1, 3, 5}
B = {6, 0, 4, 1, 5, 0, 3, 5}
print("A.issuperset(B):", A.issuperset(B))
# B is superset of A
print("B.issuperset(A):", B.issuperset(A))
輸出:
A.issuperset(B): False B.issuperset(A): True
代碼2:
# Python program to demonstrate working
# of issuperset().
A = {1, 2, 3}
B = {1, 2, 3, 4, 5}
C = {1, 2, 4, 5}
print("A.issuperset(B):", A.issuperset(B))
print("B.issuperset(A):", B.issuperset(A))
print("A.issuperset(C):", A.issuperset(C))
print("C.issuperset(B):", C.issuperset(B))
輸出:
A.issuperset(B): False B.issuperset(A): True A.issuperset(C): False C.issuperset(B): False
相關用法
注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 issuperset() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。