0

I want to know if there is a memory advantage when using this kind of method, decorated with @staticmethod and @classmethod. It could be useful when instantiating several objects of a class.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
JLD
  • 89
  • 5
  • 3
    No method is defined more than once anyway, even without any decorator. **Write what you mean.** Only worry about memory optimisation if you have an indication that it's a problem. – deceze Mar 04 '20 at 08:29
  • I really don't know if method definitions has anything to do with memory foot-print! – Kris Mar 04 '20 at 08:31
  • instances of classes in Python do not carry around copies of the methods that exist in the class. Those function objects belong to the *class*. So, `vars(some_instance)` will show you instance attributes, but you'll see, the methods aren't there. – juanpa.arrivillaga Mar 04 '20 at 08:32
  • The duplicate title isn't a great match, but the answers there should be enlightening to you nonetheless. – deceze Mar 04 '20 at 08:43
  • Thanks all for the feedback and help. I already knew the purpose of static methods and class methods, I only wanted to know the memory treatment at a low level, but with your answers it is clear. – JLD Mar 04 '20 at 15:52

0 Answers0