Courseiva
Question 248 of 498
Functions, Tuples, Dictionaries and ExceptionsmediumMultiple ChoiceObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A function is designed to process a list and returns a modified list. The developer wants to avoid unintended side effects on the original list when it is passed as an argument. Which approach best ensures the original list remains unchanged?

⚠ Common exam trap

The PCEP exam often tests the classic Python pitfall of mutable default arguments, where candidates mistakenly believe that an empty list default is reset on each call, not realizing it is a single object shared across all invocations.

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

Use None as default and create a new list inside the function

Using `None` as a default parameter and creating a new list inside the function ensures that the original list passed as an argument is never mutated. In Python, default arguments are evaluated only once at function definition time, so using a mutable default like an empty list can cause unintended side effects across multiple calls. By creating a new list inside the function (e.g., `result = list(original)`), the function operates on a copy, leaving the original list unchanged.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use a tuple as default

    Why it's wrong here

    Tuples are immutable, but the function may need to modify the sequence, which is not possible with a tuple.

  • Use an empty list as default

    Why it's wrong here

    Mutable default arguments are evaluated once at function definition, causing unexpected behavior across calls.

  • Use None as default and create a new list inside the function

    Why this is correct

    This pattern avoids mutable default arguments by creating a fresh list each call.

  • Use a global variable as default

    Why it's wrong here

    Global variables introduce side effects and are not a solution to mutable default arguments.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on PCEP

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A function is supposed to modify a list passed as argument by appending an element. However, after calling the function, the original list remains unchanged. Which is the most likely cause?

hard
  • A.The list is immutable.
  • B.The list is a tuple.
  • C.The function uses a local variable that shadows the global list.
  • D.The function reassigns the list parameter instead of mutating it.

Why D: In Python, when a list is passed to a function, the parameter refers to the same list object. If the function reassigns the parameter (e.g., `lst = [1, 2, 3]`), it only changes the local reference, not the original list. To modify the original list, the function must mutate it in-place using methods like `append()` or `extend()`, not reassign the parameter.

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.