V
V
vtaeke2020-05-29 14:19:19
Python
vtaeke, 2020-05-29 14:19:19

Why is the set correct under such an expression?

I can not understand why the set is correct with such an expression?
Highlighted in italics.

A={1,2,3,4}
print("Множество A:", A)
B={3,4,5,6}
print("Множество B:", B)
C=A|B #объединение множеств
print("Множество C=A|B:", C)
#объед множ
print("Множество A.union(B):", A.union(B))
print("Множество B.union(A):", B.union(A))
A.update(B)
print("Множество A:", A)
#измен множ В
B=B|{-1,-2,-3}
print("Множество B:", B)
C|={7,8,9}
print("Множество C:", C)


Print -> Set B: {3, 4, 5, 6, -2, -3, -1} Why is 1,2 missing, because in Set C everything is merged normally!
The book does not give a detailed answer to this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-05-29
@vtaeke

B={3,4,5,6}
B=B|{-1,-2,-3}

Where does 1 and 2 come from?
Print -> Set B: {3, 4, 5, 6, -2, -3, -1} Why is 1,2 missing,

But in C they will be from A:
A={1,2,3,4}
B={3,4,5,6}
C=A|B

Just be careful

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question