PCAP Modules and Packages Practice Question
Which TWO statements about the 'from package import *' statement are correct?
⚠ Common exam trap
The PCAP exam often tests the misconception that `from package import *` automatically imports all submodules, when in fact it only imports names from the package's `__init__.py` (or those listed in `__all__`), and submodules must be explicitly imported or listed to be included.
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
✓
If __all__ is defined in __init__.py, only the names in __all__ are imported.
When `__all__` is defined in a package's `__init__.py`, the `from package import *` statement imports only the names listed in that `__all__` list. This is the explicit mechanism Python provides to control the public API of a package when using the wildcard import syntax.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It imports the package itself as a module.
Why it's wrong here
The star form `from package import *` does not bind the package name itself in the local namespace; it brings in the attributes defined in the package's `__init__.py`. The package object is already loaded and accessible under its own name after any import, but the star import never introduces that module reference. What you receive are the names contained within the package module, not the package module as a single object.
- ✗
Without __all__, it imports all public names from the package's __init__.py and all submodules.
Why it's wrong here
Without a defined `__all__`, `from package import *` imports every name from the package's `__init__.py` that does not begin with an underscore. However, this default filtering applies only to the package's own namespace; submodules are not automatically imported merely because the asterisk is used. Any submodule must be explicitly imported within `__init__.py` or explicitly listed in `__all__` to become available through the star import.
- ✗
It imports all submodules of the package by default.
Why it's wrong here
This statement is false because the default behavior of `from package import *` does not recursively import submodules or subpackages. The import system only examines the package's `__init__.py` file and imports the names defined there, respecting underscore-prefix exclusion unless `__all__` is present. To bring submodules into scope, you must either import them directly in `__init__.py` or include their names in the `__all__` list, otherwise they stay inaccessible through the star import.
- ✓
If __all__ is defined in __init__.py, only the names in __all__ are imported.
Why this is correct
When `__all__` is defined in the package's `__init__.py`, `from package import *` imports exactly the names contained in that list. Any name not present in `__all__` is ignored, even if it is a public variable, function, or a submodule also defined in the package. This explicit list overrides the default underscore-filtering behavior and gives the package author precise control over the subset of the package's API that is exposed to star imports.
- ✓
The behavior can be customized by defining the __all__ list in __init__.py.
Why this is correct
Defining `__all__` in `__init__.py` is the standard customization hook for controlling what `from package import *` exports. This list can include variables, functions, classes, or even submodule names, and it lets you exclude internal helpers that would otherwise be public because they do not start with an underscore. By setting `__all__`, you tailor the star import to reveal only the intended public interface, rather than relying on the default rule of importing all non-underscore names.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 169 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.