PCEP Computer Programming and Python Fundamentals Practice Question
A program uses a for loop to double each element in a list: numbers = [1, 2, 3, 4, 5]; for num in numbers: num = num * 2. After execution, numbers remains unchanged. Why?
⚠ Common exam trap
The PCEP exam often tests the misconception that the loop variable is a mutable alias for the list element, leading candidates to believe reassigning it will update the list, when in fact it only rebinds the local 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
✓
Reassigning num does not modify the original list element; you need to modify via index.
In Python, the loop variable `num` is a reference to each element in the list, but reassigning `num` (e.g., `num = num * 2`) merely rebinds the local variable to a new integer object; it does not modify the original list element. To change the list in place, you must access elements by their index, such as `numbers[i] = numbers[i] * 2`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Reassigning num does not modify the original list element; you need to modify via index.
Why this is correct
Reassigning `num` only rebinds the loop variable to a new integer object; it never writes back into the list. Integers are immutable, so no in-place mutation occurs. The stem's constraint — doubling every element — requires indexed assignment, such as `numbers[i] = numbers[i] * 2`, to alter the list itself.
- ✗
The assignment creates a new list, leaving the original unchanged.
Why it's wrong here
No new list is created anywhere: num = num * 2 rebinds the loop variable to an integer, and numbers is never reassigned. It is tempting because list comprehensions and slicing do build new lists, which is the correct explanation when code assigns a derived list back to the original name.
- ✗
Lists are immutable; their elements cannot be changed.
Why it's wrong here
Python lists are mutable; append, index assignment and slice assignment all modify them in place. It is tempting because tuples and strings genuinely are immutable, so the reasoning pattern feels familiar, but here the failure is name rebinding, not element immutability.
- ✗
The variable num is a copy of the list element.
Why it's wrong here
The loop variable num is rebound to a new integer object each iteration; rebinding it never writes back into the list. It is tempting because iteration does hand out element references, and this would explain mutation of mutable nested objects, but integers are immutable and assignment replaces the name binding only.
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 →
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.