Organisez la méthode d'opération d'ensemble dans l'ensemble Python.
【set
】
X = set([1,2,3,4,5,6,1,1,1])
print(X)
# {1, 2, 3, 4, 5, 6}
Y = {9,9,9,4,5,6,7,8,9}
print(Y)
# {4, 5, 6, 7, 8, 9}
【<set>.union(set)
】
Z = X.union(Y)
print(Z)
# {1, 2, 3, 4, 5, 6, 7, 8, 9}
Z = X | Y
print(Z)
# {1, 2, 3, 4, 5, 6, 7, 8, 9}
【<set>.intersection(set)
】
Z = X.intersection(Y)
print(Z)
# {4, 5, 6}
Z = X & Y
print(Z)
# {4, 5, 6}
【<set>.symmetric_difference(set)
】
Z = X.symmetric_difference(Y)
print(Z)
# {1, 2, 3, 7, 8, 9}
Z = X ^ Y
print(Z)
# {1, 2, 3, 7, 8, 9}
【<set>.difference(set)
】
Z = X.difference(Y)
print(Z)
# {1, 2, 3}
Z = X - Y
print(Z)
# {1, 2, 3}
【<set>.issubset(set)
】
X = {1,2,3}
Y = {1,2,3,4,5}
Z = X.issubset(Y)
print(Z)
# True
Z = X <= Y
print(Z)
# True
【<set>.issuperset(set)
】
X = {1,2,3,4,5}
Y = {1,2,3}
Z = X.issuperset(Y)
print(Z)
# True
Z = X >= Y
print(Z)
# True
【<set>.isdisjoint(set)
】
X = {1,2,3}
Y = {4,5,6}
Z = X.isdisjoint(Y)
print(Z)
# True
Cet article est un article sur la migration du blog "Notes techniques pour les ingénieurs de tâches". Le blog précédent sera supprimé.
Recommended Posts