Scripting & Programming - Foundations
3.0 Credits
Objective Assessment Review (Qns &
Ans)
2025
©2025
, Question 1:
A data analytics professional is optimizing a Python script that processes large
datasets. To identify performance bottlenecks in the code, which module should be
used for profiling?
A. `timeit`
B. `cProfile`
C. `pdb`
D. `logging`
Correct ANS: B. `cProfile`
Rationale:
While the `timeit` module can benchmark small code snippets and `pdb` is a
debugger, `cProfile` is the dedicated profiler in Python that collects comprehensive
performance statistics, making it ideal for identifying bottlenecks within large-scale
data processing scripts.
---
Question 2:
Which of the following is not typically a characteristic of scripting languages
compared to compiled languages?
A. Dynamic typing
B. Interpreted execution at runtime
C. Automatic memory management
D. Requirement for explicit memory allocation
Correct ANS: D. Requirement for explicit memory allocation
Rationale:
Scripting languages like Python and JavaScript are known for their dynamic typing,
interpreted execution, and automatic garbage collection. Unlike many compiled
languages such as C or C++, scripting languages do not require explicit memory
allocation or management.
---
©2025
, Question 3:
In the context of advanced programming, which statement about closures is most
accurate?
A. A closure is a recursive function that calls itself indefinitely.
B. A closure is a function that captures variables from its lexical scope.
C. Closures are used solely for implementing object-oriented concepts.
D. A closure allows a function to modify global state without restrictions.
Correct ANS: B. A closure is a function that captures variables from its lexical
scope.
Rationale:
Closures enable a function to "remember" the environment in which it was created.
This mechanism is central in functional programming and is widely used in scripting
languages to manage state without relying on globals.
---
Question 4:
Which option best describes the concept of duck typing in dynamic programming
languages?
A. Determining an object's type based solely on its class declaration
B. Inferring an object's capabilities based on the presence of certain methods and
properties
C. Relying on compile-time type checks to enforce method signatures
D. Using interface declarations to restrict object behavior
Correct ANS: B. Inferring an object's capabilities based on the presence of
certain methods and properties
Rationale:
Duck typing centers on the principle that “if it quacks like a duck, it must be a duck.”
This means that the suitability of an object is determined by the methods and
properties it supports rather than its explicit type, promoting flexibility in dynamic
languages.
---
Question 5:
When automating file processing tasks, ensuring resource cleanup even when
©2025