Courseiva
Modules and Packages →easyMultiple Choice

PCAP Modules and Packages Practice Question

A package named 'utilities' contains a submodule 'strings'. Which import statement allows the use of the function 'reverse' defined in utilities.strings as reverse() without needing to prefix it?

⚠ Common exam trap

Test-takers frequently confuse importing a module or submodule with importing a specific attribute, leading them to pick options like A or B that still require a prefix, or option C which incorrectly assumes wildcard imports descend into submodules.

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

✓

from utilities.strings import reverse

It directly imports the `reverse` function from the `utilities.strings` submodule into the current namespace, allowing it to be called as `reverse()` without any prefix. This is the only option that imports the specific function rather than the module or package.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    import utilities.strings

    Why it's wrong here

    This statement imports the submodule, but it binds only the top-level package name `utilities` in the current namespace. The function is accessible as an attribute of the submodule, so you must call it as `utilities.strings.reverse()`; the name `reverse` is not brought into scope. Attempting to call `reverse()` directly would raise a `NameError` because the function name is not bound locally.

  • ✗

    from utilities import strings

    Why it's wrong here

    This imports the `strings` submodule from the package, binding the name `strings` in the current namespace. However, it does not import the `reverse` function, so you must still qualify the call as `strings.reverse()`. Calling `reverse()` alone would fail because `reverse` is a module-level attribute of `strings`, not a name in the current scope.

  • ✗

    from utilities import *

    Why it's wrong here

    A star import from a package imports all names defined in the package's `__all__` attribute, or if that attribute is absent, all non-underscore names bound in the package's `__init__.py` namespace. Submodules are not automatically included; unless `utilities.__all__` explicitly lists `strings` or `reverse`, neither the submodule nor the function will be imported. Thus, this option does not reliably provide access to `reverse` and may cause a `NameError`.

  • ✓

    from utilities.strings import reverse

    Why this is correct

    This statement directly locates the `reverse` function inside the `utilities.strings` submodule and binds it under the name `reverse` in the current namespace. Unlike the other options, no package or submodule qualifier is needed; you can invoke `reverse()` immediately. It is the only option that gives you the function itself rather than a module or package reference.

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 →

How Courseiva writes practice questions · Editorial policy

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.