In Python, a decorator is:
A
A tool that formats code according to PEP 8
B
A comment that documents what a function does
C
A function that wraps another function
Correct answer
D
A special variable that stores class constants
Correct answer
C. A function that wraps another function
16 views
⚔️
Challenge a friend on Python
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
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
Doubts & discussionNot sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ Inside a function, what types do *args and **kwargs collect? Next MCQ › What happens when a Python function contains the yield keyword?