1. Home
  2. Data Science
  3. Python
  4. What is a context manager in Python?

Added 25 Nov 2026

What is a context manager in Python?

  1. A type of thread
  2. A class decorator
  3. An object defining __enter__ and __exit__ for use with with Correct answer
  4. A memory manager

Correct answer

C. An object defining __enter__ and __exit__ for use with with

5 views

MCQSEXAM

Explanation

Context managers set up and tear down resources in a with block.

Reference

Asked in: Python Interview Advanced Python

https://docs.python.org/3/library/index.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs