Courseiva
Question 44 of 169
Exceptions and File I/OmediumMatchingObjective-mapped

PCAP Exceptions and File I/O Practice Question

Match each Python data structure to its mutability.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Mutable

Immutable

Mutable

Immutable

Mutable

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

list: Mutable

In Python, list, dict, and set are mutable data structures, meaning their contents can be modified. Tuple, string, and frozenset are immutable; their contents cannot be changed after creation. Common confusions include thinking tuples are mutable (they are not) or that frozensets are mutable (they are not).

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • list: Mutable

    Why this is correct

    A list is a mutable, heterogeneous sequence stored in a contiguous block of memory. Its mutability means you can modify it in place without creating a new object: assign to an index or slice, append, pop, insert, extend, or remove elements via methods like append() and pop(). Because the underlying memory address remains the same throughout such operations, lists are suitable as dynamic collections that need frequent structural changes.

  • tuple: Mutable

    Why it's wrong here

    This is incorrect because tuples are immutable sequences: once constructed, you cannot reassign, add, or delete any element. The tuple object's size and the references it holds are fixed; attempting tuple[0] = x raises TypeError. A common nuance is that a tuple containing a mutable object (e.g., a list) can still have that inner object modified, but the tuple itself never changes its collection of references.

  • dict: Mutable

    Why this is correct

    A dict is a mutable, unordered mapping stored as a hash table. Its mutability enables in-place alteration of key-value bindings: you can assign d[key] = value to add or replace an entry, use del d[key] or pop() to remove one, and employ methods like update() and setdefault() to modify the mapping. Because the hash table is allocated and resized dynamically, the dict object identity persists through these mutations, making it an efficient key-based associative container.

  • set: Immutable

    Why it's wrong here

    This is incorrect because sets are mutable, unordered collections of unique hashable objects. Sets support in-place mutations: add(), remove(), discard(), pop(), and set-update methods such as update(), intersection_update(), and symmetric_difference_update(), all of which change the set without creating a new object. In fact, a set's own mutability is exactly why it is not hashable and cannot be used as a dict key or as an element of another set, unlike its immutable sibling frozenset.

  • string: Immutable

    Why this is correct

    A string is an immutable sequence of Unicode code points. No operation can alter the characters of an existing str object; each method that appears to modify a string—such as replace(), upper(), or strip()—actually constructs and returns a new string, leaving the original intact. This immutability guarantees that strings can be safely hashed and shared across threads, and it enables internal optimizations like interning, though it also means repeated concatenation in a loop creates many intermediate objects, making ''.join() the preferred approach.

  • frozenset: Mutable

    Why it's wrong here

    This is incorrect because frozensets are the immutable version of sets: after creation, their elements cannot be added, removed, or reorganized—none of set's mutating methods (add, remove, discard, update, etc.) are available. Because frozenset's contents are fixed and its elements are themselves hashable, a frozenset is hashable and can serve as a dictionary key or as an element of another set, a capability that its mutable set counterpart does not have.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 11, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.