PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Which THREE of the following are immutable data types in Python?
⚠ Common exam trap
Python Institute often tests the misconception that all numeric types are mutable or that strings can be changed in place, leading candidates to incorrectly select list or dict as immutable.
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
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.
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 upper() returns a new str object rather than modifying the original. This immutability is what allows strings to be used as dictionary keys and satisfies the question's requirement for immutable types.
- ✓
int
Why this is correct
Integers are immutable: arithmetic such as adding one produces a distinct int object, leaving the original binding untouched. Because the value cannot change in place, int objects are hashable and usable as dictionary keys, matching the immutable-type criterion the question demands.
- ✓
float
Why this is correct
Float objects cannot be modified after creation; operations like addition yield a new float rather than mutating the existing one. This immutability makes floats hashable and safe as dictionary keys, satisfying the question's requirement that the listed type be immutable.
- ✗
list
Why it's wrong here
Lists are mutable: append, remove and item assignment all modify the object in place, so they cannot be immutable. They are tempting because they hold ordered collections like tuples, but tuples are the immutable sequence; lists are chosen when the collection must change after creation.
- ✗
dict
Why it's wrong here
A dict is mutable: keys and values can be added, removed, or reassigned after creation, so it fails the immutability test. It is tempting because dict keys must themselves be hashable and immutable, but the dictionary object as a whole is not.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
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.