PCEP variable shadowing Practice Question
Exhibit
Python 3.11.0 (default, Oct 24 2022, 14:48:10) [GCC 11.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> x = [1, 2, 3] >>> for i in range(len(x)): ... x.insert(i, x.pop()) ... >>> x [1, 2, 3]
Refer to the exhibit. What is the final value of x after executing the code?
⚠ Common exam trap
The trap is that students think the list remains unchanged, but if the loop variable is named the same as the list, the list variable is overwritten during iteration.
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
✓
[1, 2, 3]
The code uses `x` as both the list variable and the loop variable. During iteration, `x` is reassigned to each element. After the loop, `x` holds the last element, which is `3`. Since `3` is not among the options, none of the given options is correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
[1, 1, 1]
Why it's wrong here
Incorrect because after the loop, x is 3, not [1, 1, 1].
- ✗
[3, 2, 1]
Why it's wrong here
Incorrect because after the loop, x is 3, not [3, 2, 1].
- ✓
[1, 2, 3]
Why this is correct
Incorrect because the list is not preserved; x is reassigned to the last element (3).
- ✗
[3, 1, 2]
Why it's wrong here
Incorrect because after the loop, x is 3, not [3, 1, 2].
Go deeper
Related to this question
About these practice questions
One of 498 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.