Sahina Rayeesa’s Post

🧠 Python Concept: __new__ vs __init__ Object creation vs initialization 😳 ❌ What most people think 👉 __init__ creates the object ✅ Reality class Demo: def __new__(cls): print("Creating instance") return super().__new__(cls) def __init__(self): print("Initializing instance") obj = Demo() 👉 Output: Creating instance Initializing instance 🧒 Simple Explanation 👉 __new__ → creates object 👉 __init__ → initializes object 💡 Why This Matters ✔ Used in immutable types ✔ Important for metaclasses ✔ Helps in advanced object control ✔ Asked in advanced interviews ⚡ Real-World Use ✨ Singleton pattern ✨ Custom object creation ✨ Immutable objects 🐍 Creation first, then initialization 🐍 Understand object lifecycle #Python #AdvancedPython #OOP #SoftwareEngineering #BackendDevelopment #Programming #DeveloperLife

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories