PCAP Modules and Packages Practice Question
Which TWO of the following statements about Python packages are true?
⚠ Common exam trap
Python Institute often tests the misconception that an __init__.py file is always required for a directory to be a package, but since Python 3.3, namespace packages without __init__.py are valid, making option D a classic trap.
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
✓
A package can contain subpackages.
Python packages are directories that can contain subpackages (nested directories with their own __init__.py files), forming a hierarchical namespace. This allows for organized module grouping, such as `package.subpackage.module`, which is a core feature of Python's module system.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
A package can contain subpackages.
Why this is correct
A package can contain subpackages. This is correct because packages are essentially directories that map to importable namespaces, and those directories can contain other package directories. When a package directory contains an `__init__.py` (or qualifies as a namespace package), its subdirectories with `__init__.py` become subpackages, allowing hierarchical imports such as `import parent.child.module`. This nesting is fundamental to organizing large projects into logical, reusable components without forcing every module to live at the top level.
- ✓
An __init__.py file can be empty.
Why this is correct
An `__init__.py` file can be empty. The file is executed when a package is imported, but it does not have to contain any executable statements; an empty file is perfectly valid for marking a directory as a regular package. Its primary role is to signal to the import system that the directory is a package, and any initialization logic (like setting `__all__` or importing submodules) is optional. Thus, an empty `__init__.py` is a common and acceptable way to create a package.
- ✗
Packages cannot be imported using the import statement with dot notation.
Why it's wrong here
This statement is false because the `import` statement fully supports dot notation for referencing nested packages and modules. For example, `import os.path` imports the `path` submodule of the `os` package, and `from collections.abc import Iterable` uses dot notation in the module path. Dot notation is the standard syntax for traversing the package hierarchy, so imports with dots are not only possible but are the primary mechanism for accessing subpackages.
- ✗
An __init__.py file is required in every directory to make it a package.
Why it's wrong here
This statement is incorrect for Python 3.3 and later. The introduction of namespace packages allows a directory to act as a package without an `__init__.py` file, provided it is part of a namespace package spread across multiple portions on `sys.path`. If no regular package with the same name is found, the import system can still create a namespace package from a directory that lacks `__init__.py`. Therefore, while regular packages traditionally require `__init__.py`, it is not a universal requirement for every directory.
- ✗
A package is a single .py file.
Why it's wrong here
This statement is wrong because a single `.py` file is classified as a module, not a package. A package is a directory containing a collection of modules and possibly subpackages, usually identified by an `__init__.py` file (or as a namespace package without one). The distinction matters for import behavior: importing a module executes that one file, while importing a package executes its `__init__.py` and gives access to its submodules and subpackages.
Go deeper
Related to this question
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 →
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.