ProgrammingHardIBM · Deloitte · Product Company SDE

What does the following Python 3 code print? a = {1, 2, 3} b = {2, 3, 4} print(a & b, a | b, a - b, a ^ b)

  1. A. {2, 3} {1, 2, 3, 4} {4} {1, 4}
  2. B. {2, 3} {1, 2, 3, 4} {1} {1, 2, 3, 4}
  3. C. {2, 3} {1, 2, 3, 4} {1} {1, 4}
  4. D. {1, 2, 3, 4} {2, 3} {1} {1, 4}

Correct answer: C. {2, 3} {1, 2, 3, 4} {1} {1, 4}

& is intersection {2,3}; | is union {1,2,3,4}; - is set difference (in a not b) {1}; ^ is symmetric difference (in exactly one) {1,4}.

More Python Programming questions

Exams that ask this topic