Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer writes a function to update a configuration dictionary: def update_config(config, key, value): config[key] = value; return config. They call it as: my_config = {'debug': False}; result = update_config(my_config, 'debug', True). What is the value of my_config after the call, and why?

⚠ Common exam trap

The trap here is assuming that because the value True is immutable, the dictionary cannot change, when mutability of the container is what matters.

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

✓

my_config becomes {'debug': True} because the dictionary is passed by reference and modified in place.

Because dictionaries are mutable and passed into functions by object reference, assigning to a key inside the function updates the caller's dictionary. The original object is modified in place, so the change is visible outside the function without any return or reassignment. This behavior is central to Python's argument-passing semantics for mutable types.

Answer analysis

Option-by-option breakdown

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

  • ✗

    my_config remains {'debug': False} because integers and booleans are immutable and passed by value.

    Why it's wrong here

    This option incorrectly assumes that dictionary mutation is blocked by the immutability of its values. The value True is immutable, but the dictionary itself is mutable, and assignment via config[key] = value modifies the original dictionary object. The function does not reassign the parameter config, so the caller's dictionary is affected. This reflects a common misunderstanding that passing a dictionary to a function creates a full copy.

  • ✗

    A TypeError is raised because dictionaries cannot be modified inside a function.

    Why it's wrong here

    Python allows dictionaries to be modified inside functions when the function receives a reference to the mutable object. No TypeError occurs for item assignment on an existing dictionary. The function does not attempt to reassign the parameter name itself, which would be legal too. This option invents a restriction that does not exist in Python's data model.

  • ✗

    my_config becomes {'debug': True} only if the function returns the dictionary and the caller reassigns it.

    Why it's wrong here

    Reassignment by the caller is not required because the function mutates the original dictionary in place. The return statement is redundant for this side effect. Even if result is ignored, my_config would still be updated. This option confuses in-place mutation with functional-style updates that return new objects, which is not what this code does.

  • ✓

    my_config becomes {'debug': True} because the dictionary is passed by reference and modified in place.

    Why this is correct

    Dictionaries in Python are mutable objects. When passed to a function, the parameter config refers to the same dictionary object as my_config. The statement config[key] = value mutates that shared object, so the caller sees the change. No copy is made unless explicitly requested. Thus my_config now maps 'debug' to True, and result also refers to the same updated dictionary.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.