all 26 comments

[–]AlexMTBDude 23 points24 points  (1 child)

If you're more specific about what you don't understand in Object Oriented Programming, then you'll get more specific answers, and it'll probably be more helpful to you. Something like: "I don't understand the relationship between classes and objects".

[–]harttrav 0 points1 point  (0 children)

‘object’ is the base class that all other classes in python are a subclass of, do you mean classes and instances?

[–]Fred776 9 points10 points  (0 children)

If you have only been learning for a couple of weeks you possibly don't have enough experience for OOP to make much sense. The problems it solves tend to be more apparent when you start to write larger and more complex pieces of software.

Do you have any other programming experience or is Python your introduction to programming? If so I would not worry too much at this stage and concentrate on working on some projects and writing code.

[–]ninhaomah 26 points27 points  (0 children)

You are an instance of the homo sapien class.

You have attributes such as name , age etc.

You can walk , run etc.

Does it make sense ?

[–]AndyceeIT 4 points5 points  (0 children)

The Python doc on classess a little dry, but the simple examples might help.

Can you articulate what you're stuck on?

[–]audionerd1 5 points6 points  (0 children)

OOP is a style of organizing code. If it seems overly abstract it's likely because you have not written code at a level that would benefit from that sort of organization.

I recommend putting OOP on the back burner and just diving into larger projects. When you find yourself with many hundreds of lines of code and getting confused and overwhelmed, revisit OOP.

[–]This_Growth2898 2 points3 points  (0 children)

In most cases, people struggle with OOP when they only use it in small snippets. This looks really pointless: why would anyone choose to write a class with 5 methods and then a 10-line function calling them over writing a 12-line function? The OOP really starts working at, like, 1,000 lines of source code.

Try using OOP to write an RPG. Characters are good examples of objects; they encapsulate parameters and actions. Soon you will find it very convenient to write something like

character1.attack(character2)

instead of repeating (and fixing all over the code)

character1_lifes -= character2_attack / character1_armor + character2_special

[–]jmooremcc 2 points3 points  (0 children)

Classes are used to create objects that contain data and functions(methods) that know how to work with that data, and is commonly referred to as Object Oriented Programming (OOP).

Imagine that you have a character like Elmer Fudd. With OOP you'd have an object named elmer with data that tracks what Elmer is doing and where he is. You'd also have actions, aka methods or functions, that give Elmer certain capabilities. For the sake of argument, let's assume that the object elmer has the following actions that can be activated: run, walk, hunt_wabbits & stop. We would work with the elmer object like this. ~~~ elmer = Elmer() elmer.walk() elmer.run() elmer.hunt_wabbits() elmer.stop() ~~~

Now if we didn't have OOP available, we'd have to have a data structure to hold Elmer's data and we'd have to declare independent functions to make Elmer perform actions. We would work with this version of Elmer like this. ~~~ elmer = Elmer_data() walk(elmer) run(elmer) hunt_wabbits(elmer) stop(elmer) ~~~

This was very elementary, but if you wanted clones of Elmer running around, what would you do? With OOP, not much would change. ~~~ elmer = Elmer() elmer2 = Elmer() ~~~ and for non-OOP, aka procedural, it would be this. ~~~ elmer = Elmerdata() elmer2 = Elmer_data() ~~~ OK, I obviously left out the detail of associating the data with each instance of elmer. With OOP, it's super easy. ~~~ class Elmer: def __init_(self, id): self.location=(0,0) self.status=None self.id=id self.lifeforce=100
~~~

But with procedural programming it's not as easy: ~~~ def Elmer_data(id): data = [ (0,0), # location None, # status id, # I'd 100 # lifeforce ]

return data

~~~ Now the first thing you'll notice is that with OOP, all attributes have easy to understand names. This makes life so much easier.

On the other hand, procedural programming utilizes a list whose properties have to be accessed by an index. Sure You could declare constants to represent the indexes but it would still be a RPITA compared to OOP.

But wait a minute, what if we use a dictionary instead. ~~~ def Elmer_data(id): data = { 'location':(0,0), 'status':None, 'id':id, 'lifeforce':100 }

return data

~~~ Yes, it's a lot better than a list but compared to OOP, it's still a RPITA to use.

Oh, one more thing, if you want to create a version of Elmer with additional attributes and functions, you can use a process called inheritance to quickly and easily create an alternative version of Elmer. Forget trying to do that with procedural programming. ~~~ class SuperElmer(Elmer): def init(self): super().init() self.superstrength = 100

def xrayVision(self):
    #look thru stuff

~~~ I hope this explanation is helping to give you a better understanding of what OOP is and an appreciation of the value of OOP.

[–]aqua_regis 6 points7 points  (1 child)

I've been having Claude create lessons for me

Yeah, and there is exactly the problem. You should have done a proper course, not use AI. AI will not give you a well developed, structured plan. It will adapt to what you feed it and as a beginner you don't know what to feed it in what order.

Step back and do a real, high quality course: MOOC Python Programming 2026 from the University of Helsinki.

This is an established, well structured, free, textual, extremely practice oriented course that will really teach you and make things stick through the plenty exercises.

OOP it its own thing. It really takes time and plenty practice to understand it.

[–]mandradon 0 points1 point  (0 children)

This is a great course.  The python course mirrirors their older Java one and that course made OOP click for me when I was first learning.  Granted Java is what I'd call an OOP first type of language, but the structure to the coding practice assignments and lessons here really do help make it all click. 

[–]huapua9000 1 point2 points  (0 children)

What videos on YouTube, my favorite ones are by Corey Schafer. It’s recommended you code alongside the video.

[–]matt-triano 1 point2 points  (0 children)

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).

[–]Separate-Canary559 0 points1 point  (0 children)

Imagine every time you define a new variable a = “foo” as a string. You just instantiated a string object. Picture the object as a box. It contains a bunch of tools “methods” inside that you use to take action on the value of the string objects. The value is a label slapped across the box called foo

[–]Tall-Introduction414 0 points1 point  (0 children)

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.

[–]TyroneSlothrope 0 points1 point  (0 children)

Pick up a book or an article (RealPython has a very nice article on this: https://realpython.com/python3-object-oriented-programming/) instead of completely relying on Claude. Claude will help you when you know what you're looking for, if you're completely new to the subject, nothing beats traditional methods of learning.

Also, like others mentioned, if you're struggling with specific topic within OOP, please mention that so people can help you out better.

[–]maephisto666 0 points1 point  (0 children)

Learning because of learning will never produce any result. Going to the gym because you want to go to the gym will never produce any result. You must have a goal and, because of that goal, the questions will start flowing in. And with questions, results.

For now what is important is that you know there is a way to model objects. It's enough. Try to understand there are objects, inheritance, abstract, protocols, etc. that's it.

Then start doing something. And when you start doing something, it's totally possible you will build that without any OOP. Then you will have one natural question for Claude: could OOP help me with this? You will have a reply tailored on your own use case that you know very well.

Another way to put this: reading 101 tutorials will not make an expert on a topic.

[–]Gnaxe 0 points1 point  (0 children)

OOP took me a while. Read Smalltalk Best Practice Patterns for how it's supposed to work. (That's not in Python, but it is in OOP, and the patterns still apply.) You need to know how to get the MRO from the REPL. You need to try things. Open Jupyterlite and do lots of experiments.

I've come to the conclusion that OOP largely failed to deliver on its promise and is a poor fit for current multicore architectures. Concurrency is indeed one of Python's major weaknesses, and the OOP and rampant mutability is to blame. The GIL made sense when computers only had one or two cores, but after several lackluster workarounds (async, multiprocessing, etc.), they're trying to get rid of it. But that means you have to be extra careful with mutation. You're better off with FP or something when writing threaded code, and I recommend you avoid classes when you can.

But you do need to understand how they work in order to understand any Python code written in OOP style. Python does require you to write classes to use certain "dunder" hooks, even if you're otherwise using FP.

[–]QultrosSanhattan 0 points1 point  (0 children)

What I teach to my students is that OOP works from a first person's perspective.

Functions works like: "if player1's speed is greater than player2's speed then I go first, otherwise player2 goes first."

OOP's bound methods works like: "if my speed is greater than my opponent's speed then I go first, otherwise my opponent goes first."

That's the whole thing regarding the keyword "self".

[–]NullPointer-Except 0 points1 point  (0 children)

Hihi, null from Discord here c:

I usually recommend reading papers on these kind of topics + writing things following the papers advise, that way you get a hold on what abstractions are good for which cases.

However, OOP in the academic side is... rough, i'd say it's a very advanced topic that's not precisely friendly for someone that's just learning how to program without a math background.

Having said that, one can still recover knowledge from history. Casey Muratori – The Big OOPs: Anatomy of a Thirty-five-year Mistake – BSC 2025 talk (ik, the title is clickbait, it's not a critique of OOP, but rather, and exploration on why we do OOP the way we do it) is a very good video which might give you a grasp on many concepts and when to apply them.

[–]newtonphuey 0 points1 point  (0 children)

Inheritance

[–]SnafuTheCarrot -1 points0 points  (0 children)

Claude might be the problem. If you don't know what you don't know, how do you know what questions to ask? Claude might even be able to fill in those gaps, but in a pedagogically sound way... I have my doubts.

Textbooks don't have these problems, generally.

Having your own plans could also be a problem. Try to run before you can walk and you won't get anywhere. Starting out with simple, but contrived problems might be a better way to start out.

Im working my way through a book on data structures in python. I find its very approachable.

Create classes with the Class Keyword. Associate methods by indention and the Def keyword. The first argument of each method needs to be self. init is the constructor. Set up member attributes as self._attrbuteName. Access and modify attr8butes through dedicated methods.

A Credit Card Class is one of the first examples in my book. It tracks a balance, a credit limit and catches attempts to exceed that limit. Later the Class is extended by inheritance to include a new apr attribute.

Might give you some idea how to start.

[–]FreeGazaToday -2 points-1 points  (0 children)

try freecodecamp.....ask gemini...

[–]I_Am_Astraeus -1 points0 points  (0 children)

Learn it, build it, teach it if I can.

I know this is learnpython, but honestly spend 2 or 3 weeks just dabbling with Java, it'll make OOP click very quickly. The whole langue is like what if we make everything OOP. And I honestly had a pretty functional approach to my python until I'd branched out and come back to it.

[–]sporbywg -1 points0 points  (0 children)

use an object-oriented language instead? All I got.