Introduction to Programming in Python
3.0 Credits
Objective Assessment Review (Qns &
Ans)
2025
©2025
, Multiple Choice Questions
Question 1:
A data analyst working with large datasets in Python is considering
different approaches to iterate over data without loading an entire list
into memory. Which of the following best describes the key benefit of
using a generator expression over a list comprehension?
A. It evaluates elements eagerly, ensuring faster access.
B. It yields one element at a time using lazy evaluation, reducing memory
usage.
C. It reduces code complexity by eliminating loops entirely.
D. It provides built-in caching for repeated iterations.
Correct ANS: B. It yields one element at a time using lazy evaluation,
reducing memory usage.
Rationale:
Generator expressions compute values on the fly and yield one item at a
time, which is especially beneficial when processing very large datasets.
This lazy evaluation minimizes memory consumption compared to list
comprehensions that generate the entire list in memory.
---
Question 2:
In Python, which advanced feature allows a function to capture variables
from its enclosing scope—even after that scope has finished execution—
and thus maintain state?
A. Recursion
B. Closure
C. Lambda function
D. Decorator
Correct ANS: B. Closure
©2025
, Rationale:
A closure is a function object that remembers values in enclosing scopes
even if they are not present in memory. This capability is vital for
encapsulating state and behavior, which helps in building higher-level
abstractions in Python programming.
---
Question 3:
Which built-in Python module is primarily used to write asynchronous
code using the async/await syntax, enabling non-blocking I/O
operations?
A. threading
B. multiprocessing
C. asyncio
D. concurrent.futures
Correct ANS: C. asyncio
Rationale:
The `asyncio` module provides a framework for asynchronous
programming in Python by running an event loop that supports non-
blocking I/O, making it essential for real‑time applications and scenarios
where high concurrency is required without resorting to multi-threading.
---
Question 4:
What Python feature allows you to extend or modify the behavior of
functions or methods without altering their source code, effectively
wrapping them with additional functionality?
A. Inheritance
B. Decorators
C. Context managers
©2025