ProgrammingHardProduct-company MCQ pattern

How many of the following statements about Python are correct? (i) A tuple that contains a list can be used as a dictionary key. (ii) A frozenset can be an element of a set. (iii) Strings support item assignment, e.g. s[0] = 'x'. (iv) list.sort() returns the sorted list.

  1. A. Only two
  2. B. Only one
  3. C. Only three
  4. D. All four

Correct answer: B. Only one

Only (ii) is true: a frozenset is immutable and hashable. (i) fails because hashing the tuple hashes the list inside it, which raises TypeError. (iii) strings are immutable. (iv) sort() returns None.

More Python Programming questions

Exams that ask this topic