PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
A developer writes a function that assigns a new value to an element of a list passed as an argument. After the function returns, the caller observes that the original list has been modified. The developer wants a second function that appends an item to a list but leaves the caller's list unchanged. Which definition achieves this?
⚠ Common exam trap
The trap here is assuming that any assignment inside a function, including augmented assignment on a list parameter, creates a local copy and therefore protects the caller's object.
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
✓
def add_item(lst, item): lst = lst + [item] return lst
Passing a list to a function passes a reference to the same object, so any in-place method such as append, insert, or += alters the caller's data. Only creating a new list object, as with the concatenation lst + [item], avoids mutating the caller's list while still producing an appended result that can be returned.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
def add_item(lst, item): lst = lst + [item] return lst
Why this is correct
The expression lst + [item] creates a brand-new list object and rebinds the local name lst to it. The caller's original list object is never mutated, so after the function returns the caller still sees the unchanged list. The new list is returned for the caller to use if desired, which satisfies the requirement of appending without affecting the caller's list.
- ✗
def add_item(lst, item): lst += [item] return lst
Why it's wrong here
The augmented assignment lst += [item] on a list invokes in-place concatenation through __iadd__, which extends the existing list object rather than creating a new one. The caller's list therefore gains the item. Because the requirement is to leave the caller's list unchanged, this implementation does not meet the goal.
- ✗
def add_item(lst, item): lst.insert(0, item) return lst
Why it's wrong here
insert mutates the list in place and also places the item at index 0 instead of appending at the end. Both aspects contradict the requirement: the caller's list is modified, and the position is wrong. Even though a value is returned, the original list object has already been changed, so the caller observes the modification.
- ✗
def add_item(lst, item): lst.append(item) return lst
Why it's wrong here
Calling lst.append(item) mutates the list object in place, and because lists are passed by object reference, the caller's list is modified. This is precisely the behaviour the developer wants to avoid. Returning the list does not undo the mutation; the caller already sees the extra element, so this definition fails the stated requirement.
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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.