🛠️ToolsShed

Calculatrice d'Ensembles

Calculez l'union, l'intersection, la différence et la différence symétrique de deux ensembles.

Questions Fréquentes

Implémentation du Code

# Set operations in Python
A = {1, 2, 3, 4, 5}
B = {3, 4, 5, 6, 7}

# Union: all elements in A or B
union = A | B
print(union)           # {1, 2, 3, 4, 5, 6, 7}

# Intersection: elements in both A and B
intersection = A & B
print(intersection)    # {3, 4, 5}

# Difference: elements in A but not B
diff_AB = A - B
print(diff_AB)         # {1, 2}

diff_BA = B - A
print(diff_BA)         # {6, 7}

# Symmetric difference: in A or B but not both
sym_diff = A ^ B
print(sym_diff)        # {1, 2, 6, 7}

# Subset checks
print({1, 2}.issubset(A))    # True
print(A.issuperset({1, 2}))  # True

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.