What a set is
A set is a collection of different things, called its elements. We write a set in curly braces: A = {1, 2, 3, 4, 5}. Order does not matter, and each element is simply in the set or not.
The symbol ∈ means "is an element of". 3 ∈ A is true, because 3 sits inside the box of A. 6 ∉ A, because 6 is not in A. Python asks the same question with the keyword in.
Now B = {4, 5, 6, 7}. 4 and 5 are already in A, so the box of B is drawn around them too. Nothing is copied: each element appears once. Overlapping boxes like these are a Venn diagram.
Combining sets
The union A ∪ B holds every element that is in A, in B, or in both. Python writes it A | B. Each element is listed once, so A ∪ B = {1, 2, 3, 4, 5, 6, 7}.
The intersection A ∩ B keeps only the elements that are in both sets: the overlap of the two boxes. Python writes it A & B. Here A ∩ B = {4, 5}.
The difference A − B keeps what is in A but not in B: take the part of B out of the box of A. So A − B = {1, 2, 3}. Order matters here: B − A = {6, 7}.
The symmetric difference A △ B keeps what is in exactly one of the sets: in A or in B, but not in both. Python writes it A ^ B. It is the union minus the overlap: {1, 2, 3, 6, 7}.
Size and subsets
The size of a set, written |A|, is how many elements it has: |A| = 5 and |B| = 4. Adding them counts 4 and 5 twice, so take the overlap away once: |A ∪ B| = 5 + 4 − 2 = 7.
C is a subset of A, written C ⊆ A, when every element of C is also in A. Take C = {4, 5}: both are in A, so C ⊆ A is true. In Python, C <= A gives True.
The universe U holds every element we are talking about; here U = {1, 2, ..., 8}. The complement of A is everything in U that is not in A: U − A = {6, 7, 8}.
Try it in the Python prompt
;; step 1/10 · A set of elements
>>> A = {1, 2, 3, 4, 5}
>>> A
{1, 2, 3, 4, 5}
>>> {5, 4, 3, 2, 1} == A # order does not matter
True
>>> {1, 1, 2} == {1, 2} # nor does repeating
True
Building a set throws duplicates away: set([1, 2, 2, 3]) gives {1, 2, 3}. A set has no order either, so {1, 2} == {2, 1} is True. Symbols and Python: ∈ is in, ∪ is |, ∩ is &, − is -, △ is ^ and ⊆ is <=.