PCAP Modules and Packages Practice Question
A programmer wants to use the sqrt function from the math module. Which import statement is most efficient?
⚠ Common exam trap
Python Institute often tests the misconception that `import module.function` (e.g., `import math.sqrt`) is valid. Python allows `import package.submodule` only when the target is a submodule, but `sqrt` is a function, not a submodule. For functions, use `from module import function` or `import module` and then `module.function`.
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 math import sqrt
`from math import sqrt` binds only the `sqrt` function into the current namespace, avoiding name collisions with other math functions. While the `math` module itself is still fully loaded, this form avoids introducing extra global names and provides direct access to `sqrt`, which is more convenient and slightly faster than attribute lookup with `math.sqrt`. It is the most appropriate when only that one function is needed.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
from math import sqrt
Why this is correct
This is the correct approach because it explicitly imports only the sqrt function from the math module into the current namespace. After execution, you can call sqrt(9) directly without a module prefix, which improves readability and reduces the chance of name collisions. It is a targeted, efficient way to bring in only the specific functionality you need.
- ✗
import math.sqrt
Why it's wrong here
This is invalid syntax in Python. The import statement can use dot notation to address submodules or packages, but sqrt is a function defined inside the math module, not a separate submodule. The interpreter will raise an ImportError or a syntax error because it expects a module path, not a callable. To use sqrt without importing the whole math module, you need the form 'from math import sqrt'.
- ✗
from math import *
Why it's wrong here
The wildcard import 'from math import *' imports all public names from math into the global namespace, which does make sqrt available. However, it is discouraged because it can cause name conflicts with existing variables or functions, pollutes the namespace, and makes the source of names unclear. It unnecessarily imports many items when only sqrt is needed, contrary to Python's philosophy of explicit is better than implicit.
- ✗
import math
Why it's wrong here
With 'import math', the math module is loaded as an object, and you must use the fully qualified name math.sqrt(9) to call the function. While this works and is commonly used, it is less direct and slightly more verbose because every usage requires the 'math.' prefix. It also imports the entire module, which is fine in this case but not as focused as a direct import of just the sqrt function.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 421 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.