set theory
SET THEORY – A set is an unordered collection of unique elements.
Let:
A = {1, 2, 3}
B = {3, 4, 5}
| Notation | Operation | Python | Result |
| A∩B | Intersection | print(A & B) |
{ 3 } |
| A∪B | Union | print(A | B) |
{ 1, 2, 3, 4, 5 } |
| A-B | Difference (or relative complement) | print(A – B) |
{ 1, 2 } |
| B-A | Difference (or relative complement) | print(B – A) |
{ 4, 5 } |
| A∆B | Symmetric difference | print(A ^ B) |
{ 1, 2, 4, 5 } |
A = {1, 2, 3}
B = {3, 4, 5}
print(A & B)
print(A | B)
print(A - B)
print(B - A)
print(A ^ B)