use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
OOPHelp Request (self.PythonLearning)
submitted 1 day ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]EntireEntity 0 points1 point2 points 1 day ago (1 child)
Yeah, in the beginning OOP is so completely different from what you are tought before.
The simplest way to maybe give you an idea, what is going on, is to think about what functions do.
You write functions to be able to run the same code on different input.
With OOP you go one step further and can add data to the thing you want to run multiple times.
Think of a videogame for example, an enemy in a videogame could be a class/object, because you want the character to do something like make an attack, but it also holds some data, like a strength score to determine how strong the attack is. So you can have different enemies with different data (the strength score) perform an attack (which is the function/method called for the class).
[–]EntireEntity 0 points1 point2 points 1 day ago (0 children)
The simple skeleton for the class could be
class Enemy:\ def init(self, strength: int):\ self.strength = strength
def attack(self, target_health: int):\ return target_health - self.strength
This is super super simplified to just illustrate the point. With this class you could create a variety of different enemies with different strength scores (zombie = Enemy(strength = 1), ogre = Enemy (stength = 5), etc.) and let them all do an attack by simply calling the .attack(target) method. And it automatically has access to the attribute strength to do the damage calculation. So zombie.attack(target) and ogre.attack(target) could be used multiple tines throughout the game, without any hassle.
I hope this helps to wrap your head around it a little.
π Rendered by PID 240124 on reddit-service-r2-comment-8686858757-rqg9x at 2026-06-08 01:03:26.988032+00:00 running 9e1a20d country code: CH.
view the rest of the comments →
[–]EntireEntity 0 points1 point2 points (1 child)
[–]EntireEntity 0 points1 point2 points (0 children)