ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
a = {1, 2}
b = a
a |= {3}
c = frozenset(a)
a = a | {4}
print(b, c, a, type(c | {9}).__name__)
  1. A. {1, 2} frozenset({1, 2, 3}) {1, 2, 3, 4} frozenset
  2. B. {1, 2, 3, 4} frozenset({1, 2, 3}) {1, 2, 3, 4} set
  3. C. {1, 2, 3} frozenset({1, 2, 3}) {1, 2, 3, 4} frozenset
  4. D. {1, 2, 3} frozenset({1, 2, 3}) {1, 2, 3, 4} set

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

|= updates the set in place (b sees 3), while a | {4} builds a new set and rebinds only a. Binary operations on a frozenset return the type of the left operand, a frozenset.

More Python Programming questions

Exams that ask this topic