Courseiva
Functions, Tuples, Dictionaries and ExceptionshardMultiple ChoiceObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

Exhibit

def modify_dict(d):
    d['key'] = 'new_value'
    d = {'another': 'dict'}

my_dict = {'key': 'old_value'}
modify_dict(my_dict)
print(my_dict)

Refer to the exhibit. What is the output?

⚠ Common exam trap

The PCEP exam often tests the distinction between a method's return value and the object it modifies, leading candidates to mistakenly think the output is `None` (the return value of `update()`) instead of the updated dictionary itself.

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

{'key': 'new_value'}

The `update()` method on a dictionary modifies the dictionary in place by updating the value for an existing key. Since `my_dict` already contains the key `'key'`, calling `update({'key': 'new_value'})` changes its value to `'new_value'`, and the method returns `None`. The print statement outputs the updated dictionary, which is `{'key': 'new_value'}`.

Answer analysis

Option-by-option breakdown

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

  • {'key': 'old_value'}

    Why it's wrong here

    Incorrect. The dictionary was modified.

  • {'another': 'dict'}

    Why it's wrong here

    Incorrect. The reassignment does not affect the outer variable.

  • None

    Why it's wrong here

    Incorrect. The function does not return anything, but the dictionary is printed.

  • {'key': 'new_value'}

    Why this is correct

    Correct. The original dictionary is mutated.

About these practice questions

This PCEP question is part of Courseiva's 498-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 →

How Courseiva writes practice questions · Editorial policy

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.