如果集合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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。