HomeInterview QuestionsWhat are the key differences between constructors …

What are the key differences between constructors and decorators in Python?

🟢 Easy Conceptual Junior level
1Times asked
May 2026Last seen
May 2026First seen

💡 Model Answer

In Python, a constructor is a special method called __init__ that runs when a new instance of a class is created. It is used to initialize instance attributes and set up the object's initial state. A decorator, on the other hand, is a higher‑order function that takes another function or class and returns a modified version of it. Decorators are applied using the @ syntax and are typically used to add behavior such as logging, authentication, or caching without changing the original function’s code. Key differences: constructors are tied to object instantiation and belong to classes, while decorators are independent functions that wrap existing callables. Constructors run automatically during object creation; decorators must be explicitly applied. Constructors cannot be reused across different classes without inheritance, whereas decorators can be applied to any function or method. Example: class MyClass: def __init__(self, x): self.x = x; @log_decorator def my_func(): pass.

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 — invisible to screen sharing.

Get Assisting AI — Starts at ₹500