ProgrammingVery hardInfosys HackWithInfy · TCS CodeVita

What does the following Python 3 code print? a = frozenset([1, 2, 3]) try: a.add(4) except AttributeError: print("AttributeError")

  1. A. frozenset({1, 2, 3, 4})
  2. B. TypeError
  3. C. None
  4. D. AttributeError

Correct answer: D. AttributeError

frozenset is immutable and has no add() method at all, so calling it raises AttributeError, not a mutation error.

More Python Programming questions

Exams that ask this topic