ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
a = {1, 2, 3, 4}
b = {3, 4, 5}
print(a ^ b, a - b, b <= a, a | b == {1, 2, 3, 4, 5})
  1. A. {1, 2, 5} {1, 2, 3, 4} False True
  2. B. {1, 2, 5} {1, 2} False True
  3. C. {3, 4} {1, 2} False True
  4. D. {1, 2, 5} {1, 2} True False

Correct answer: B. {1, 2, 5} {1, 2} False True

^ is symmetric difference, giving {1, 2, 5}. a - b keeps {1, 2}. b is not a subset of a because 5 is missing, and the union equals {1, 2, 3, 4, 5}.

More Python Programming questions

Exams that ask this topic