🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Tuples and Sets: all 15 questions

Quiz: Tuples and Sets · Question 11 of 15

What does this print? (code)

What does this print?

a = {1, 2, 3}
b = {3, 4}
print(sorted(a | b), sorted(a ^ b))
  1. A.[3] [1, 2, 4]
  2. B.[1, 2, 3, 4] [1, 2, 4]
  3. C.[1, 2, 3, 4] [3]
  4. D.[1, 2, 3, 3, 4] [1, 2, 4]
Answer & explanation

Correct answer: [1, 2, 3, 4] [1, 2, 4]

| is the union (all items, no repeats); ^ keeps items that are in exactly one of the sets.

Can you get the rest right without peeking?

Take the timed Quiz: Tuples and Sets quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →