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.

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. Commented Mar 4, 2020 at 8:29
  • I really don't know if method definitions has anything to do with memory foot-print! Commented Mar 4, 2020 at 8: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. Commented Mar 4, 2020 at 8:32
  • The duplicate title isn't a great match, but the answers there should be enlightening to you nonetheless. Commented Mar 4, 2020 at 8: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. Commented Mar 4, 2020 at 15:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.