Argha Chatterjee’s Post

🚀 Day 3/30 – Python OOPs Challenge 💡 __init__() Constructor in Python In Day 2, we learned about Class & Object. Today let’s understand how objects get initial data. 🔹 What is __init__()? __init__() is a constructor. It runs automatically when we create an object. We use it to initialize (set) values for an object. 🔹 Simple Example: ``` class Student: def __init__(self, name, roll_no): self.name = name self.roll_no = roll_no def display(self): print(self.name, self.roll_no) s1 = Student("Argha", 101) s1.display() ``` 🔹 Why use __init__()? - To pass data while creating an object - To avoid writing extra code later - Makes code clean and readable 📌 Key takeaway: __init__() helps us give starting values to objects. 👉 Day 4: Instance variables vs Class variables (coming tomorrow) 👍 Like | 💬 Comment | 🔁 Share 📍 Follow me to learn Python OOP step by step #Python #OOP #LearningInPublic #30DaysOfPython #CodingJourney

🧠 Practice Question – Day 3 Create a class `Book` with: - title - author - price Use `__init__()` to initialize values. Create one object and print the details. Try it yourself 👇   Comment your code 🚀

To view or add a comment, sign in

Explore content categories