0

I'm just starting to learn about Python class and static methods. I don't know how Python static methods differ from other languages' static methods, so I don't know if the answer to my question maybe already exists somewhere else on a question pertaining to another language.

It seems to me that Python static methods are useful only as a way to put a set of functions into a namespace, to "containerize" them. Are there any other uses for them that aren't at least equally well accomplished by just having a separate function or by having a class/instance method?

NeutronStar
  • 2,057
  • 7
  • 31
  • 49
  • 1
    "It seems to me that Python static methods are useful only as a way to put a set of functions into a namespace" -> Yup, that's it exactly. Any function that logically occupies the same functional space as a class, but isn't instance-specific and doesn't need a reference to the class itself to do its job is a useful thing to `staticmethod`. – Adam Smith Jan 10 '19 at 23:07
  • I almost never use them. Only once or twice where the namespacing was really critical, mostly where I see it being very useful for code-completion. Other than that, I almost always prefer module-level functions – juanpa.arrivillaga Jan 11 '19 at 00:11

0 Answers0