Python中的 issuperset()
如果集合 A 的所有元素都占据作为参数传递的集合 B,则Python set issuperset() 方法返回 True,如果 B 的所有元素都不存在于 A 中,则返回 false。这意味着如果A 是 B 的超集,则返回真的;否则为假
Python issuperset()语法:
A.issuperset(B)
checks whether A is a superset of B or not.
Python issuperset()返回:
True if A is a superset of B; otherwise false.
Python issuperset() 示例
示例 1:issubset() 与两个集合的工作
Python
# 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))
Python
# 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
示例 2: issubset() 与三个集合的工作
Python
# 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