Courseiva
Strings →easyMultiple Select

PCAP Strings Practice Question

Which TWO of the following are immutable in Python?

⚠ Common exam trap

Python Institute often tests the misconception that strings are mutable because they support indexing and slicing, but candidates forget that any operation that appears to change a string actually returns a new string object, leaving the original unchanged.

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

✓

Tuple

Tuple (B) is immutable because once created, its elements cannot be added, removed, or changed. This is enforced by Python's internal structure: tuples are stored as a fixed-length array of PyObject pointers, and any attempt to modify them raises a TypeError.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Set

    Why it's wrong here

    Sets are mutable containers; elements can be added via add() or removed via discard()/remove(), and operations like union_update mutate the set in place. Because their hash-based implementation relies on elements being hashable but not on the set's own hash, the set itself is not hashable and cannot be used as a dictionary key or set member. This mutability disqualifies sets from being immutable.

  • ✓

    Tuple

    Why this is correct

    Tuples are immutable sequences; once created, their contents cannot be changed, added, or removed. Although tuples can contain mutable objects (like a list), the tuple's own structure and element references are fixed, making it hashable only if all elements are hashable. This immutability allows tuples to serve as dictionary keys when they contain only immutable elements.

  • ✓

    String

    Why this is correct

    Strings are immutable sequences of Unicode characters. Any operation that appears to modify a string, such as concatenation or replace(), actually creates a new string object, leaving the original unchanged. In CPython, this immutability enables interning, safe sharing, and use of strings as dictionary keys without risk of in-place modification.

  • ✗

    Dictionary

    Why it's wrong here

    Dictionaries are mutable mappings; you can add new key-value pairs, delete existing keys, or change values associated with keys. The internal hash table is resized and rehashed as the dictionary grows, so the object's identity persists while its contents change. Consequently, dictionaries are unhashable and cannot be used as keys in other dictionaries.

  • ✗

    List

    Why it's wrong here

    Lists are mutable sequences; you can modify individual elements by index, append or extend the list, remove items, and reorder via methods like sort() or reverse(). Because lists can be changed in place, their hash value would be unstable, so they are unhashable and cannot be used as set members or dictionary keys. This in-place mutability is what distinguishes lists from tuples.

About these practice questions

One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.