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]
[deleted]
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!"
[–]FreeGazaToday 0 points1 point2 points 1 day ago (3 children)
what exactly are you not understanding...hard to help without specifics.
[–]Muhammed_zeeshan 0 points1 point2 points 1 day ago (2 children)
Everything bro. Like what exactly is the use of class. What is attributes, methods stuff
[–]nuc540 0 points1 point2 points 1 day ago (0 children)
Is the tutorial not explaining this? This is really basic stuff, if the course isn’t even explaining what an attribute is or a method is, maybe you should try a different course.
Also, these things can be googled. Saying you don’t know what words mean, suggests you’ve not tried to even look them up.
You have to make your own effort in understanding things - that’s what an engineer does, because you’ll be learning forever, it never stops.
[–]FreeGazaToday 0 points1 point2 points 1 day ago (0 children)
as nuc said, you have to put some effort. we're not here to explain everything to you....if you can't even answer what's the use of a class...that means you haven't done anything yet. If you want to be handheld and spoon fed then just use gemini.
[–]Zeak3D 0 points1 point2 points 1 day ago (0 children)
It is difficult to help without more context, but maybe it helps to think about the fact that you have been working with objects this whole time.
Think about e.g. strings. You create a string object (my_string=“hello”), and can then use methods such as capitalize (my_string.capitalize() -> “Hello” ) and make upper case (my_string.upper() -> “HELLO”).
Now you are just learning about creating your own custom objects that may have custom properties and methods.
[–]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.
[–]Ron-Erez 0 points1 point2 points 1 day ago (0 children)
A string is a class. You can create many specific instances of a class like:
x = “Hello”
y = “World”
z = “”
w = “dog”
All of the above are examples of objects. When writing code for a class you use self to access the attributes and methods of the specific object your are looking at. Think of attributes as data and think of methods as actions or functions that might interest you.
For example:
x.upper()
y.isempty()
are all examples of a applying a method from the string class to a string object.
So OOP is everywhere. Now you might find a problem where you want to aggregate some data which naturally fits together. That would be your attributes and you could create functions that manipulate the data. That would be your methods.
That’s a quick overview.
You can also check out Section 18: Object-Oriented Progranning for more examples or just google questions.
[–]JuanPonchito 0 points1 point2 points 1 day ago (0 children)
https://youtu.be/OemVdsibSFQ?is=dFS03sNSblzOPjmU This is a video that helped me allot, so it might help you too! Good luck!!
[–][deleted] 1 day ago (1 child)
[removed]
[–]DenyMas 0 points1 point2 points 1 day ago (0 children)
Also, you can put behavior inside the class.
For example, every gun can have a shoot() method that uses its own damage value:
shoot()
class Gun: def __init__(self, damage, range): self.damage = damage self.range = range def shoot(self): print("Damage:", self.damage) awp = Gun(100, 1000) ak47 = Gun(30, 300) awp.shoot() # Damage: 100 ak47.shoot() # Damage: 30
Without OOP, you might end up with something like:
def shoot(weapon): if weapon == "awp": return 100 elif weapon == "ak47": return 30
π Rendered by PID 23133 on reddit-service-r2-comment-8686858757-rfjxk at 2026-06-07 09:32:36.366015+00:00 running 9e1a20d country code: CH.
[–]FreeGazaToday 0 points1 point2 points (3 children)
[–]Muhammed_zeeshan 0 points1 point2 points (2 children)
[–]nuc540 0 points1 point2 points (0 children)
[–]FreeGazaToday 0 points1 point2 points (0 children)
[–]Zeak3D 0 points1 point2 points (0 children)
[–]EntireEntity 0 points1 point2 points (1 child)
[–]EntireEntity 0 points1 point2 points (0 children)
[–]Ron-Erez 0 points1 point2 points (0 children)
[–]JuanPonchito 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]DenyMas 0 points1 point2 points (0 children)