PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Which TWO data types are immutable in Python?
⚠ Common exam trap
The PCEP exam often tests the misconception that 'immutable' means the variable cannot be reassigned, but immutability refers to the object itself, not the variable binding; candidates may incorrectly think lists or dicts are immutable because they can reassign the variable.
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 operations like concatenation or replace() return new string objects rather than modifying the original. Option E (int) is correct because integers are immutable numeric objects; any arithmetic operation such as x += 1 rebinds the name to a new int object instead of altering the existing one. The unmarked options do not belong because set (B), list (C), and dict (D) are all mutable container types whose contents can be modified in place via methods like add(), append(), and item assignment.
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 store an immutable sequence of Unicode code points, so any operation that appears to modify one — concatenation, slicing, `replace()` — returns a new `str` object rather than altering the original in place. This satisfies the stem's immutability constraint, since no method can change an existing string's contents after creation.
- ✗
set
Why it's wrong here
Sets are mutable: methods such as add, remove and discard modify the set in place, so it cannot be immutable. It is tempting because sets, like frozensets, are unordered and cannot be indexed, which is a separate property from immutability.
- ✗
list
Why it's wrong here
Lists are mutable: append, extend, insert and item assignment all modify the list in place, so it fails the immutability requirement. It is tempting because lists and tuples share ordered, indexable sequence behaviour, but only tuples are immutable.
- ✗
dict
Why it's wrong here
Dictionaries are mutable: assigning to an existing key, adding keys and using update all change the dictionary in place. It is tempting because dictionary keys must themselves be hashable and immutable, but that constraint applies to the keys, not to the dictionary.
- ✓
int
Why this is correct
Integers are immutable in Python; any arithmetic operation produces a new int object rather than modifying the existing one. Rebinding a name to a different value creates a fresh object, which is why ints can safely serve as dictionary keys.
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 of the following is an immutable data type in Python?
easy- ✓ A.tuple
- B.set
- C.list
- D.dict
Why A: A tuple is immutable because once created, its elements cannot be changed, added, or removed. This is enforced by Python's internal structure: tuples are stored as a fixed-length array of object references, and no methods exist to modify them in place.
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.