JNCIA-DevOps: Juniper Networks Certified Associate – Automation (2021) — Question 5

Which Python code block is an example of a context manager?

Answer options

Correct answer: C

Explanation

The correct answer is C, as it correctly uses the 'with' statement, which is a hallmark of context managers in Python. Options A and D do not utilize context management features, while option B employs a try-except block, which is not the same as a context manager.