Courseiva
Modules and Packages →easyMultiple Choice

PCAP Modules and Packages Practice Question

A module 'config.py' contains a variable 'settings' that is a dictionary. Another script does: from config import settings. Then the script modifies settings['key'] = 'new_value'. What happens?

⚠ Common exam trap

Python Institute often tests the misconception that from ... import ... creates a copy of the object, when in fact it only binds a reference to the same mutable object in memory.

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

✓

The change is reflected in config.settings because it is the same object.

Python's import statement binds the name 'settings' in the importing module's namespace to the same dictionary object that exists in config.py. Since dictionaries are mutable, modifying settings['key'] directly mutates the shared object, and the change is visible through config.settings as well.

Answer analysis

Option-by-option breakdown

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

  • ✗

    The config module is reloaded and the change is lost.

    Why it's wrong here

    Python does not automatically reload modules when you modify their attributes. When a module is imported once, it is cached in sys.modules and subsequent imports return the same module object. No reloading happens unless you explicitly call importlib.reload(config) (now deprecated in 3.12 in favor of importlib.reload), so the change is not 'lost' due to a reload — the module simply retains its in-memory state.

  • ✗

    The script gets a copy of the dictionary, so config.settings is unchanged.

    Why it's wrong here

    Importing a module or a name from it does not create a copy of the object. The statement 'import config' and 'from config import settings' both bind references to the exact same dictionary object that was created when the module was first executed. Because dictionaries are mutable containers, any in-place modification performed through one reference (e.g., settings['key'] = value) directly mutates the shared object, so config.settings reflects the change.

  • ✓

    The change is reflected in config.settings because it is the same object.

    Why this is correct

    The variable 'settings' in the script and 'config.settings' point to the same dictionary instance in memory. In Python, assignment and import bind names to objects rather than copying the object's data. Since the dictionary is mutable, performing an in-place operation such as settings['new_key'] = value updates the single shared dictionary; no extra mechanism is needed for the change to be visible through config.settings.

  • ✗

    An error occurs because settings is read-only.

    Why it's wrong here

    A module attribute that holds a dictionary is not read-only; Python dictionaries are mutable containers by default. There is no built-in protection preventing modification of a dictionary stored as a module-level variable, unless you have specifically wrapped it in a custom read-only mapping or used a class with __slots__ (which applies to attributes, not their container contents). No error occurs when mutating the dictionary; the underlying object is designed to allow item assignment and update.

About these practice questions

This PCAP question is part of Courseiva's 421-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 PCAP 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 PCAP exam.