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 is working on a project that requires the use of a third-party package hosted on a private repository. The developer wants to ensure that the package can be imported without specifying the full repository URL each time. Which approach should be taken?
Explanation: Option C is correct because configuring the repository URL in pip's configuration file (e.g., `pip.conf`, `pip.ini`, or `~/.config/pip/pip.conf`) or in `requirements.txt` using the `--index-url` or `--extra-index-url` option allows pip to resolve the package from the private repository automatically. This approach ensures that the package can be installed and imported without manually specifying the full URL each time, as pip will use the configured index to locate and download the package.
A Python script imports the module 'my_module'. The developer wants to ensure that when the script is run directly, it executes a specific function, but when imported as a module, that function is not executed. Which code snippet achieves this?
Explanation: Option B is correct because the `if __name__ == '__main__':` guard is the standard Python idiom to check whether a script is being run directly (as the main program) or being imported as a module. When the script is executed directly, Python sets the special variable `__name__` to the string `'__main__'`, so the function `run()` is called. When the script is imported, `__name__` is set to the module's name (e.g., `'my_module'`), so the condition fails and `run()` is not executed.
A 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: Option D is correct because in Python, the `__all__` variable in a package's `__init__.py` explicitly controls which names are exported when `from package import *` is used. By setting `__all__ = ['mean', 'std']`, the developer ensures that only the functions `mean` and `std` from `stats.py` are imported into the namespace, as Python will look up these names in the package's scope after executing the `__init__.py` file. This overrides the default behavior where all public names (those not starting with an underscore) would be exported.
A developer is troubleshooting an ImportError: 'No module named 'config''. The config module is located in a subdirectory 'utils' relative to the script. The script's current working directory is the parent of 'utils'. Which of the following lines, added to the script, will resolve the issue?
Explanation: The ImportError occurs because Python's module search path (sys.path) does not include the 'utils' subdirectory. Adding 'utils' to sys.path via sys.path.append('utils') tells Python to look inside that directory for modules, resolving the import. Option B is correct because it extends the search path to include the directory containing the config module, without altering the script's working directory or incorrectly appending a file path.
A developer wants to import a specific function 'calculate' from a module named 'formulas' without importing the entire module. Which import statement should be used?
Explanation: Option C is correct because the `from module import name` syntax in Python allows you to import a specific function (or other attribute) from a module directly into the current namespace, without importing the entire module. This avoids unnecessary memory usage and keeps the namespace clean by only bringing in the needed `calculate` function.
+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 →