D335 ITSW 3126 Introduction to
Programming in Python
Objective Assessment Review
(Questions & Solutions)
2025
©2025
, Question 1 (Multiple Choice)
Question:
Which Python feature allows you to modify or extend the behavior of a
function or class without permanently altering its source code?
Options:
A. Generators
B. Context managers
C. Decorators
D. Comprehensions
Correct ANS:
C. Decorators
Rationale:
Decorators wrap a function or class, introducing additional behavior at
definition time without changing the actual code body. This pattern is
invaluable in network automation—for example, to add logging,
authentication, or caching to functions that interact with network
devices.
---
Question 2 (Fill-in-the-Blank)
Question:
The built-in Python library __________ facilitates asynchronous
programming by providing an event loop, which is particularly useful
when handling multiple I/O-bound network operations concurrently.
ANS:
asyncio
©2025
, Rationale:
`asyncio` is designed to write concurrent code using the async/await
syntax, enabling the efficient management of multiple network
connections or API calls in modern network automation scripts.
---
Question 3 (True/False)
Question:
True or False: Python supports traditional function overloading (i.e.,
defining multiple functions with the same name but different
parameters).
Correct ANS:
False
Rationale:
Python does not support conventional function overloading as seen in
statically typed languages. Instead, developers use default arguments,
variable-length argument lists, or manually check argument types within
a single function definition.
---
Question 4 (Multiple Response)
Question:
Select all that apply: Which of the following Python built-in types are
immutable?
Options:
A. List
B. Tuple
©2025
, C. String
D. Dictionary
E. Frozenset
Correct ANS:
B. Tuple, C. String, E. Frozenset
Rationale:
Tuples, strings, and frozensets are immutable; once they are created,
their values cannot be changed. This immutability is beneficial in
networking contexts where predictable behavior is required, such as in
caching configurations. Lists and dictionaries are mutable.
---
Question 5 (Multiple Choice)
Question:
Which keyword is used in Python to catch and handle exceptions that
may occur during the execution of network automation scripts?
Options:
A. try/except
B. catch/throw
C. do/catch
D. begin/rescue
Correct ANS:
A. try/except
Rationale:
The `try/except` block in Python is the standard method for catching
exceptions, ensuring that scripts (for example, when remotely connecting
to a device) can gracefully handle errors without crashing.
©2025
Programming in Python
Objective Assessment Review
(Questions & Solutions)
2025
©2025
, Question 1 (Multiple Choice)
Question:
Which Python feature allows you to modify or extend the behavior of a
function or class without permanently altering its source code?
Options:
A. Generators
B. Context managers
C. Decorators
D. Comprehensions
Correct ANS:
C. Decorators
Rationale:
Decorators wrap a function or class, introducing additional behavior at
definition time without changing the actual code body. This pattern is
invaluable in network automation—for example, to add logging,
authentication, or caching to functions that interact with network
devices.
---
Question 2 (Fill-in-the-Blank)
Question:
The built-in Python library __________ facilitates asynchronous
programming by providing an event loop, which is particularly useful
when handling multiple I/O-bound network operations concurrently.
ANS:
asyncio
©2025
, Rationale:
`asyncio` is designed to write concurrent code using the async/await
syntax, enabling the efficient management of multiple network
connections or API calls in modern network automation scripts.
---
Question 3 (True/False)
Question:
True or False: Python supports traditional function overloading (i.e.,
defining multiple functions with the same name but different
parameters).
Correct ANS:
False
Rationale:
Python does not support conventional function overloading as seen in
statically typed languages. Instead, developers use default arguments,
variable-length argument lists, or manually check argument types within
a single function definition.
---
Question 4 (Multiple Response)
Question:
Select all that apply: Which of the following Python built-in types are
immutable?
Options:
A. List
B. Tuple
©2025
, C. String
D. Dictionary
E. Frozenset
Correct ANS:
B. Tuple, C. String, E. Frozenset
Rationale:
Tuples, strings, and frozensets are immutable; once they are created,
their values cannot be changed. This immutability is beneficial in
networking contexts where predictable behavior is required, such as in
caching configurations. Lists and dictionaries are mutable.
---
Question 5 (Multiple Choice)
Question:
Which keyword is used in Python to catch and handle exceptions that
may occur during the execution of network automation scripts?
Options:
A. try/except
B. catch/throw
C. do/catch
D. begin/rescue
Correct ANS:
A. try/except
Rationale:
The `try/except` block in Python is the standard method for catching
exceptions, ensuring that scripts (for example, when remotely connecting
to a device) can gracefully handle errors without crashing.
©2025