Python OOP Day 10: Classes and Self

Day 10 of #30DaysOfPython ✅ Today was the biggest day so far. And also the most confusing one. Object Oriented Programming. OOP. The thing everyone says will "change how you think about code." They weren't wrong. But they also didn't warn me it would feel like learning Python all over again from scratch. 😅 I've been writing functions all week. A function does one thing. You call it. It returns something. Clean and simple. A class is different. A class is a blueprint. It describes what something is and what it can do — all in one place. The example that finally made it click: I was thinking about it all wrong. I kept trying to understand classes in the abstract. Then I wrote a Student class. It has a name, a department, and a GPA. It has a method that introduces itself. And suddenly — oh. This is just a way to group related data and behaviour together. That's it. That's the whole idea. The thing that got me: self. Every method inside a class takes self as the first parameter. I kept forgetting it. Python kept yelling at me. After the fifth TypeError: takes 1 positional argument but 2 were given I finally understood — self is how the method knows which specific object it's talking to. Without it, the method has no idea whose data to use. Now I respect self. A lot. What I covered today: 1)class keyword and the basic blueprint structure 2)__init__ — the constructor that runs when you create an object 3)Instance variables vs class variables 4)Methods — functions that live inside a class 5)Creating multiple objects from one class Day 10 done. One third of the challenge complete. 🎉 👇 OOP was a genuine mindset shift for me today. What's the concept in programming that took you the longest to truly click? I'd love to know I'm not alone! #Python #30DaysOfPython #OOP #ObjectOrientedProgramming #BuildInPublic

  • text

To view or add a comment, sign in

Explore content categories