0

Purpose of Static Methods

i get @classmethods, they will spawn a new instance of the class, but @staticmethods? the only difference between just creating a method in a class and declaring it as a @staticmethod is that you dont have to pass a "self" to it, so why go through the trouble if declaring it at all, "self" is afterall shorter to type than "@staticmethod"

23rd Oct 2021, 8:56 AM
Peter Kuik
Peter Kuik - avatar
1 Answer
+ 1
@static methods use nothing from the class itself, hence, why it's missing the self parameter that allows for it's own attributes and methods to be called. If you write a method and find there was no reason to use any class attributes, it should be a static method
23rd Oct 2021, 8:58 AM
Slick
Slick - avatar