Courseiva
Question 57 of 498
Functions, Tuples, Dictionaries and ExceptionseasyMultiple ChoiceObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A system administrator has a Python script that uses a tuple to store immutable configuration parameters, such as server address and port. A new business requirement arises: one of these parameters (the port number) must be changeable at runtime without restarting the script. The other parameters must remain immutable. The administrator wants to minimize changes to the existing codebase and maintain clarity. Which approach best satisfies the requirement while keeping the code maintainable?

⚠ Common exam trap

Watch out — candidates often assume namedtuple._replace() mutates the tuple in place, but it actually returns a new instance, which does not satisfy the requirement for runtime mutation without restarting the script.

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

Store all parameters in a dictionary and update the port as needed

A dictionary allows direct mutation of the port value without affecting the immutability of other parameters. This satisfies the requirement of changing only the port at runtime while keeping the rest of the configuration unchanged, and it minimizes code changes by simply replacing the tuple with a dict and using assignment to update the port key.

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 namedtuple and use the _replace() method to create a new instance with the updated port

    Why it's wrong here

    namedtuple is immutable; _replace() creates a new object, which is inefficient and may confuse other parts of the code.

  • Replace the entire tuple with a list to allow updates

    Why it's wrong here

    A list is mutable, but using a list instead of a tuple for all parameters may lead to accidental changes elsewhere.

  • Store all parameters in a dictionary and update the port as needed

    Why this is correct

    A dictionary is mutable and allows easy updates while clearly showing which parameters are changeable.

  • Convert the tuple to a list, update the port, then convert back to a tuple each time

    Why it's wrong here

    This is inefficient and unnecessarily complex, involving repeated conversions.

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

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.