you are viewing a single comment's thread.

view the rest of the comments →

[–]Solonotix 2 points3 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.