What is a decorator in Python? How would you write your own decorator, for example one that measures how long a function takes to run?
~4 min by voice
How to approach it
The interviewer wants to see whether you understand how decorators work under the hood: functions are first-class objects, the wrapper is a closure, and @ is syntactic sugar. They also check whether you can write a correct decorator on the spot, one that passes arguments through and returns the result.
The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.