20+ practice questions focused on Modules and Packages — one of the most tested topics on the Certified Associate Python Programmer PCAP exam. Each question includes a detailed explanation so you learn why the right answer is correct.
Start Modules and Packages PracticeA developer creates a package named 'analytics' with the following structure: analytics/ __init__.py stats.py models/ __init__.py regression.py The developer wants the statement 'from analytics import *' to import only the functions 'mean' and 'std' from stats.py. What should be added to analytics/__init__.py?
Explanation: To make `from analytics import *` export only `mean` and `std`, the desired functions must be imported into the package namespace (e.g., `from analytics.stats import mean, std`) AND `__all__ = ['mean', 'std']` must be set in analytics/__init__.py. Option B alone imports everything public from stats.py, so it does not satisfy 'only'. Option D sets `__all__` but does not import the names. None of the provided options is fully correct.
A developer is creating a package that contains a subpackage. The subpackage has an __init__.py file that imports a module named 'helper' from the parent package. Which import statement in the subpackage's __init__.py will correctly import 'helper'?
Explanation: Both option A and option D are correct ways to import 'helper' from the parent package. Option A uses an absolute import, explicitly naming the parent package (mypackage), which is unambiguous and follows best practices. Option D uses a relative import with '..' to refer to the parent package, which is a valid syntax and also works when the subpackage is part of a package. Relative imports are concise but can be less clear. Options B and C are incorrect: 'from . import helper' would try to import from the current package, and 'from ... import helper' uses too many dots, referring to the grandparent, not the parent.
Which TWO of the following are valid ways to import a module named 'math' and give it an alias 'm'?
Explanation: Only B. Option B uses the correct syntax `import math as m` to import the entire math module with alias m. Option A is invalid because the asterisk (*) cannot be combined with an alias in a `from ... import` statement. Option C is missing the `as` keyword. Option D uses `alias` which is not a valid keyword; the correct keyword is `as`. Option E imports a specific function (sin) from math, not the module itself; therefore it does not satisfy the requirement to import the module and give it an alias.
You are a developer at a company that builds a data processing pipeline. The pipeline consists of several Python modules organized in a package called 'pipeline'. The package structure is: pipeline/ __init__.py load.py transform.py analyze.py The pipeline is deployed on a server where Python 3.8 is installed. The server also has a globally installed package called 'pipeline' (from a different project) in the site-packages directory. When you run your scripts that import 'pipeline', you get unexpected behavior because Python is importing the wrong package. You need to ensure that your local 'pipeline' package is used instead of the global one. You cannot uninstall the global package because it is used by another application. You have the following options: A) Modify the PYTHONPATH environment variable to include the directory containing your 'pipeline' package before the site-packages directory. B) Rename your local 'pipeline' package to something else and update all imports. C) Use a virtual environment specific to your project and install your package there. D) Add an __init__.py file with a special import hook to override the global package. Which course of action is the most appropriate and reliable?
Explanation: Using a virtual environment creates an isolated Python environment where you can install your local 'pipeline' package without affecting or being affected by the globally installed package. This is the most reliable approach as it ensures that Python's import system will search the virtual environment's site-packages before the global site-packages, preventing any naming conflicts. Virtual environments are the standard Python best practice for managing project-specific dependencies and avoiding package name collisions.
A developer is troubleshooting a Python application that fails to import a custom module named 'utils'. The file 'utils.py' exists in the same directory as the main script. Which of the following is the most likely cause of the import failure?
Explanation: When a Python script is executed directly (e.g., python main.py), Python sets sys.path[0] to the directory containing the script. Since utils.py is in the same directory as the main script, it should be found by the import system. Therefore, a failure to import utils.py is not caused by the directory being absent from sys.path. The most plausible cause from the given options is that utils.py contains a syntax error, which raises a SyntaxError during compilation and prevents the module from being loaded.
+15 more Modules and Packages questions available
Practice all Modules and Packages questions1. Baseline your knowledge
Start with 10 questions to gauge your current understanding of Modules and Packages. This tells you whether you need a concept refresher or just practice.
2. Review every explanation
For each question — right or wrong — read the full explanation. Understanding why an answer is correct is more valuable than knowing the answer itself.
3. Focus on exam traps
Modules and Packages questions on the PCAP frequently use trap wording. Look for subtle differences in answers that test your precision, not just general knowledge.
4. Reach 80% consistently
Do repeated sessions until you score 80%+ three times in a row. Then move to mixed-mode practice to test cross-topic recall under realistic conditions.
The exact number varies per candidate. Modules and Packages is tested as part of the Certified Associate Python Programmer PCAP blueprint. Practicing with targeted Modules and Packages questions ensures you can handle any format or difficulty that appears.
Yes. Courseiva provides free PCAP practice questions across all exam topics and domains. The platform includes topic-based practice, mock exams, missed-question review, bookmarked questions, and readiness tracking — no account required.
Difficulty is subjective, but Modules and Packages is a high-priority exam concept tested in multiple ways — direct recall, scenario analysis, and command-output interpretation. Consistent practice is the best way to build confidence.
Launch a full Modules and Packages practice session with instant scoring and detailed explanations.
Start Modules and Packages Practice →