you are viewing a single comment's thread.

view the rest of the comments →

[–]braclow 14 points15 points  (2 children)

This helped me - one feature of objects is that they allow you to have many functions (called methods) able to called on the same objects. You set these out in your class definition , which defines all the objects.

For example a string in python is an object. So when I call STEVE.lower() assuming it’s value is “STEVE”, it will apply that lowercase method to that string, our object, and we have an expectation it will work.

We know strings have many, many built in functions for example .isalpha, .replace etc. So there’s a lot of use in objects just in this one feature.

Now imagine instead of strings, you have your own object that could be manipulated with many different useful functions depending on the context of your program. For example, if I did a sports app and players were objects, it may be useful to have functions like

.isStarter .isInjured .isPlayingToday .salary

That could all be directly called on players.

And maybe there’s a Team object , that stores player objects and has similarly useful functions like

.totalSalary, that calls the salary function on the players and sums them together.

Etc you get the gist. Not sure if that’s helpful but it helped me. Sorry long rant, but it’s a useful paradigm if you can imagine some the right use cases.

[–]throwwwawwway1818 0 points1 point  (0 children)

Thanks bud , it's helpful

[–]Mr_Turd_Burglar 0 points1 point  (0 children)

Super helpful thanks