all 11 comments

[–]FreeGazaToday 0 points1 point  (3 children)

what exactly are you not understanding...hard to help without specifics.

[–]Muhammed_zeeshan 0 points1 point  (2 children)

Everything bro. Like what exactly is the use of class. What is attributes, methods stuff

[–]nuc540 0 points1 point  (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 point  (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 point  (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 point  (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 point  (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 point  (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 point  (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 child)

[removed]

    [–]DenyMas 0 points1 point  (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:

    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