PCAP Modules and Packages Practice Question
Which TWO of the following are true about importing modules using the import statement?
⚠ Common exam trap
Python Institute often tests the misconception that 'import module as alias' creates a separate copy of the module, when in reality it only creates an additional reference to the same module object in sys.modules.
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 module is executed only once on the first import.
Python caches imported modules in the sys.modules dictionary. When a module is imported for the first time, it is executed and its code is stored; subsequent imports of the same module simply retrieve the cached object from sys.modules without re-executing the module's code. This ensures that module-level initialization runs only once, preventing side effects like repeated resource allocation or redefinition of global variables.
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 module is executed only once on the first import.
Why this is correct
When a module is first imported, its top-level code runs, and the resulting module object is stored in the sys.modules dictionary. Subsequent import statements for the same module retrieve that cached object and bind it to the requested name, skipping re-execution of the module body. This ensures that expensive initializations and side effects (such as establishing database connections) happen exactly once per process.
- ✗
Relative imports can be used in scripts executed as the main module.
Why it's wrong here
Relative imports depend on the __package__ attribute to determine the module's position in the package hierarchy. When a file is executed directly (e.g., python script.py), Python sets __name__ to '__main__' and leaves __package__ empty, so a relative import like 'from . import sibling' has no package context to resolve against. As a result, such imports raise an ImportError, meaning they are only valid when the file is imported as part of a package.
- ✗
Importing a module with a different name using 'as' creates a copy of the module.
Why it's wrong here
The 'as' syntax binds the already-imported module object to a new name in the current namespace; no new module is created. Since the module is stored as a single object in sys.modules after its first import, the original name and the alias reference the exact same object, and any changes made through one name are visible through the other. It is a lightweight reference, not a duplicate of the module's contents.
- ✗
Circular imports always cause an ImportError.
Why it's wrong here
Circular imports can succeed if the import cycle completes before an attribute is actually accessed at module load time. For example, if module A imports B, and B imports A, but B only references A's attributes inside functions (which are executed later), the import may finish without error once A has been partially initialized. Although circular imports can lead to AttributeError or ImportError if an attribute is accessed before it is defined, the claim that they always fail is incorrect.
- ✓
Importing a module adds it to sys.modules.
Why this is correct
The import system uses sys.modules as a cache: after the code for a module is loaded and executed, the module object is inserted into this dictionary with its fully qualified name as the key. Any later import of the same module finds the entry in sys.modules and immediately returns the existing object, which is why imports are cheap and idempotent. Manually inserting an entry into sys.modules can even simulate an already-imported module, though this is rarely done.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 421 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 →
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.