HomeInterview QuestionsWhat are decorators and why do we need to use them…

What are decorators and why do we need to use them?

🟢 Easy Conceptual Fresher level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

Decorators in Python are a syntactic construct that allows you to wrap a function or method with another function, modifying its behavior without changing its code. They are defined using the @decorator syntax above the target function. Decorators are useful for cross‑cutting concerns such as logging, authentication, caching, or input validation. For example, a @login_required decorator can check if a user is authenticated before executing a view function. Because decorators are applied at definition time, they keep the core logic clean and promote code reuse. They also enable the creation of higher‑order functions that can dynamically alter behavior based on runtime conditions.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500