Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 107 pages
Exam (elaborations)

PCAP-31-03 Practice Test: 250 Exam Questions for Python Certification

Document preview thumbnail
Preview 4 out of 107 pages

This practice test is meticulously organized into focused modules to optimize your study time. You will master the math module for advanced calculations, the random module for generating pseudo-random numbers, and the platform module for system identification. Deep dives into the sys and os modules will solidify your understanding of Python's interaction with the operating system, file paths, and environment variables. Beyond the core modules, this resource ensures you are fully prepared for questions on Python's import system, relative vs. absolute imports, and the use of __name__ and __init__.py. It also covers the essential tools for a Python developer, including pip for package installation, the creation of virtual environments, and standard packaging practices using and . Each question includes a clear, correct answer and an in-depth rationale that explains not just the "what," but the "why." This approach helps you understand the underlying concepts, identify common pitfalls, and reinforce your knowledge, ensuring you are ready to pass the certification exam on your first attempt.

Content preview

PCAP-31-03 - MODULE 1 - MODULES,
PACKAGES & PIP|TEST BANK- 250 QUESTIONS
WITH CORRECT ANSWERS AND RATIONALES
2026/2027

---



TOPIC A: Basic Import Mechanics (Questions 1-25)



1. What is the primary purpose of the `import` statement in Python?

- A) To execute a system shell command

- B) To bring a module's namespace into the current namespace

- C) To delete an unused variable

- D) To compile Python bytecode

Correct Answer: B

Rationale: The `import` statement loads a module and makes its objects
(functions, classes, variables) available to the current script, effectively
bringing its namespace into scope.



2. Which syntax correctly imports only the `sqrt` function from the `math`
module?

- A) `import sqrt from math`

- B) `from math import sqrt`

- C) `import math.sqrt`

,- D) `include math.sqrt`

Correct Answer: B

Rationale: The `from ... import ...` syntax is specifically designed to import
specific attributes directly into the current namespace without importing the
entire module.



3. What happens when you use `import math` and then try to call `sqrt(9)`
without prefixing it?

- A) It prints 3.0 successfully

- B) It raises a `NameError` because `sqrt` is not defined in the global
namespace

- C) It automatically imports sqrt as well

- D) It raises a `SyntaxError`

Correct Answer: B

Rationale: When you use `import math`, the `sqrt` function is bound to the
`math` namespace. You must call it as `math.sqrt(9)`. Calling `sqrt(9)`
searches the global namespace and fails.



4. Which statement allows you to call `floor(3.7)` directly without a prefix?

- A) `import math`

- B) `import math as m`

- C) `from math import floor`

- D) `from math import *`

Correct Answer: C (and technically D, but C is the specific correct practice)

,Rationale: `from math import floor` binds the `floor` function directly to the
global namespace, allowing direct calls. While `from math import *` also
does this, it is generally discouraged.



5. What is the effect of the `as` keyword in an import statement (e.g.,
`import numpy as np`)?

- A) It copies the module to a new file named `np.py`

- B) It creates an alias (shortcut) for the module name

- C) It validates the module syntax

- D) It installs the module globally

Correct Answer: B

Rationale: The `as` keyword allows you to assign a different name (alias) to
the imported module, which is useful for shortening long module names or
avoiding naming conflicts.



6. Which of the following is a syntax error?

- A) `import math, sys`

- B) `from math import pi, e`

- C) `import math as m`

- D) `from math import as m`

Correct Answer: D

Rationale: The syntax `from math import as m` is invalid. `as` is used to
alias the module itself (e.g., `import math as m`) or an imported function
(e.g., `from math import sqrt as sq`). The syntax in D is missing the function
name before `as`.

, 7. How does Python handle importing the same module multiple times in a
single script?

- A) It executes the module code multiple times

- B) It raises an `ImportError` on the second attempt

- C) It imports it once and caches it in `sys.modules`

- D) It creates a separate copy for each import

Correct Answer: C

Rationale: Python uses a caching mechanism. The first import executes the
module code; subsequent imports simply retrieve the cached module object
from `sys.modules`, preventing redundant execution.



8. Which built-in function returns a list of all names defined in the current
local namespace?

- A) `locals()`

- B) `globals()`

- C) `dir()`

- D) `vars()`

Correct Answer: C

Rationale: While `locals()` and `globals()` return dictionaries, `dir()` without
arguments returns a sorted list of names in the current local scope. When
used with a module argument, it lists the module's attributes.



9. What will `dir(math)` return after importing `math`?

- A) A list of all file names in the math directory

Document information

Uploaded on
August 27, 2026
Number of pages
107
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$17.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
1
Items
51
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions