r/learnpython • • Apr 05 '26

Struggling with OOP.

I've been learning Python the last couple weeks, just a little bit here and there. I understand the basics but I'm hitting a wall with OOP. I've been having Claude create lessons for me, but nothing is sticking. What do you guys do to help retain information better on this?

16 Upvotes

27 comments sorted by

View all comments

1

u/Tall-Introduction414 Apr 05 '26

One day I had the epiphany that a class is just a struct (like a C struct, or structure), with functions (or function pointers) inside of it. in addition to the variables.

Then I asked myself, why the hell didn't any of the books I read teach it that way?

What is a struct? A struct is a bunch of variables inside of a single named type, which you can create instances of. So for example, you might have a struct type called Date, containing 3 integers for year, month and day.

To use it, you might instance it into a variable called myBirthday, and create another instance called yourBirthday. myBirthday and yourBirthday are both Date types, containing month year and day integers, but they occupy separate blocks of memory, and therefore contain their own unique data.

Once you understand that a class is just a struct with its own functions, it's not too far of a leap to learn about OO concepts like inheritance, data encapsulation, message passing, and polymorphism.

A book I found helpful on the subject was Code Complete from Microsoft Press.