1. Home
  2. Data Science
  3. Python
  4. In Python, a decorator is:

Added 2 Nov 2026

In Python, a decorator is:

  1. A tool that formats code according to PEP 8
  2. A comment that documents what a function does
  3. A function that wraps another function Correct answer
  4. A special variable that stores class constants

Correct answer

C. A function that wraps another function

16 views

MCQSEXAM

Explanation

Writing @timer above def f is shorthand for f = timer(f). Decorators add logging, caching (functools.lru_cache) or access checks without changing the original function's code.

Reference

Asked in: NTS, Python Developer Interviews

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