PCEP Computer Programming and Python Fundamentals Practice Question
Which TWO of the following are immutable data types in Python?
⚠ Common exam trap
The PCEP exam often tests the distinction between mutable and immutable types by pairing tuple (immutable) with list (mutable), hoping candidates confuse tuple's immutability with list's mutability, or mistakenly think that because a tuple can contain mutable objects, the tuple itself is 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
✓
str
Option A (str) is correct because Python strings are immutable: once created, their characters cannot be changed in place, and any operation like concatenation or slicing returns a new string object. Option E (tuple) is correct because tuples are immutable sequences; after creation you cannot add, remove, or reassign their elements, and attempting to do so raises a TypeError. The unmarked options do not belong because set (B), dict (C), and list (D) are all mutable container types, meaning their contents can be modified in place via methods such as add(), update(), or append().
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
str
Why this is correct
Strings cannot be altered after creation; any operation such as concatenation or slicing returns a new str object rather than modifying the original in place. This immutability makes str hashable and usable as dictionary keys, satisfying the question's requirement for an immutable Python data type.
- ✗
set
Why it's wrong here
Sets are mutable: elements can be added or discarded in place via add() and remove(), so they are not immutable. It is tempting because sets are unordered collections of hashable elements, and would be correct if the question asked which type stores unique values with fast membership testing.
- ✗
dict
Why it's wrong here
Dictionaries are mutable: keys and values can be added, removed or reassigned in place, so they cannot serve as immutable types. It is tempting because dicts are hashable containers used as lookup structures, and would be the right answer if the question asked which type maps keys to values.
- ✗
list
Why it's wrong here
Lists are mutable: elements can be reassigned, appended or deleted in place, so they fail the immutability requirement. It is tempting because lists are the default ordered sequence in Python, and would be correct if the question asked which type supports indexed, changeable ordering.
- ✓
tuple
Why this is correct
Tuples are immutable sequences: once constructed, their elements cannot be reassigned, appended or removed, and any slicing or concatenation produces a new tuple. This contrasts with lists, which support in-place mutation, so tuple satisfies the question's requirement for an immutable data type.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP 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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which THREE of the following are immutable data types in Python?
medium- ✓ A.str
- ✓ B.int
- ✓ C.float
- D.list
- E.dict
Why A: In Python, str (A) is immutable because string objects cannot be modified in place—operations like concatenation or replace() return a new string rather than altering the original. int (B) is immutable since integer objects have a fixed value once created, and arithmetic operations produce new int objects instead of changing existing ones. float (C) is likewise immutable, as floating-point values cannot be changed after creation and any arithmetic yields a new float object. By contrast, list (D) is mutable because elements can be added, removed, or reassigned in place, and dict (E) is mutable because key-value pairs can be inserted, updated, or deleted after the dictionary is created.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP 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 PCEP exam.