classmethod and staticmethod

Common method within a class is bound to its instance, i.e. the function takes the instance as the first argument by default.

classmethod is bound to its class type, i.e. the function takes the class as the first argument by default.

staticmethod is not bound to anything.

Use Cases

classmethod is often used to create inheritable alternative constructors or factory methods.

staticmethod is used for more organizable and stylistic codes.

Reference: https://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod

results matching ""

    No results matching ""