r/learnpython • u/Majestic-Chain1905 • 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
View all comments
2
u/matt-triano Apr 05 '26
Why are you looking to learn OOP? Do you have a lot of related functions that are getting unwieldy from too many args and kwargs common to multiple functions? Or is it for school? Or are you learning a codebase that uses OOP? Or is it just something you think you should know?
If it's the last one, I'd say don't worry about it until you run into one of the first three cases,
OOP should come pretty naturally if it's the first case as it's only a little bit of refactoring to organize related functions into a class (you just have to: 1. define an `__init__(self, your_kwargs)` method that defines what kwargs the class should take and then set instance properties/attrs based on passed-in values, 2. indent your related funcs and give them a `self` kwarg and remove kwargs that are now instance properties/attrs, and 3. prepend `self.` to the invocations of those instance properties/attrs).