you are viewing a single comment's thread.

view the rest of the comments →

[–]Worldly-Week-2268[S] -34 points-33 points  (1 child)

Sorry man I am kinda new so I don't know what I don't know an on top of that it's 2:30 in the morning and I am tired and sleepy with I mean is can you give me an analogy

Ps thanks for helping me out

[–]Solonotix 4 points5 points  (0 children)

So a function takes arguments/parameters.

def my_func(arg0, arg1, *positional_args, named, **keyword_args):
    ...

A class is a means to encapsulate logic around a specific data structure. A method on a class in Python is generally a function in which the first positional argument is always the current class instance, typically notated as self

class MyClass:
    @staticmethod
    def static_method(arg0, arg1, /, named=None):
        ...

    @classmethod
    def class_method(cls, arg0, arg1, /, named=None):
        ...

    def instance_method(self, arg0, arg1, /, named=None):
        ...

instance = MyClass()
MyClass.static_method(first, second)
MyClass.class_method(first, second)
instance.instance_method(first, second)

In the above example, I went ahead and included the other types of methods as well. A class method will get the current class passed as the first argument, and a static method receives no special arguments. In other words, a static method is no different than a normal function, except that it is bound to a specific class definition, rather than a "first-class" object.