PCEP Control Flow, Loops, Lists and Logic Practice Question
Given the code: x = [1, 2, 3] y = x y.append(4)
print(x)
What is the output?
⚠ Common exam trap
Python Institute often tests the distinction between variable assignment and object copying, trapping candidates who mistakenly think `y = x` creates a separate copy of the list, leading them to choose option B.
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, 4]
In Python, variables hold references to objects, not the objects themselves. When `y = x` is executed, both `x` and `y` point to the same list object in memory. The `y.append(4)` method modifies that shared list in-place, so the change is reflected when `x` is printed, outputting `[1, 2, 3, 4]`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Error
Why it's wrong here
No exception occurs: y = x binds the same list object, and append mutates it in place, so printing x succeeds. It tempts because aliasing surprises developers, but an error would require an illegal operation such as indexing out of range or mutating during iteration.
- ✗
[1, 2, 3]
Why it's wrong here
Both names reference one list object, so append(4) mutates the shared list and x prints [1, 2, 3, 4]. It tempts because it assumes assignment copies the list, which would hold only if y were a copy made via x.copy() or list(x).
- ✓
[1, 2, 3, 4]
Why this is correct
Assignment binds y to the same list object as x, not a copy. Calling append mutates that shared object in place, so the single list now holds four elements and printing x reflects the change.
- ✗
[1, 2, 3, 4, 5]
Why it's wrong here
Only one element is appended, so the list holds four items, not five. It tempts because it presumes append adds multiple values or that both x and y each contribute an element, whereas append takes a single argument and mutates the shared object once.
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.