Interview Question

What is constructor in Python?

__new__ creates an instance; __init__ initializes it.

💡 Concept ✅ Quick Revision 🐍 Python

Answer

Instance creation uses __new__ to create an object and __init__ to initialize it. • __init__ is an initializer, not the method that allocates the instance. • Python calls __init__ after __new__ returns an instance of the class. • __init__ must return None.

💡 Simple Example

class User: def __init__(self, name): self.name = name print(User('Maya').name)

Output

Maya

⚡ Quick Revision

__new__ creates an instance; __init__ initializes it.