title: what is the use and when to use @classmethod in python?
body: <p>I have never used @classmethod and I do not think of any examples to use it, I know how it works but I do not know when it's time to use it for example</p>
  
  <pre><code>class Example:
      def __init__(self,param1,param2):
          self.param1 = param1
          self.param2 = param2
      @classmethod
      def my_method(cls,param1,param2):
          return cls(param1,param2)
  
  example = Example.my_method(1,2)
  print(example)
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>&lt;__main__.Example object at 0x02EC57D0&gt;
  </code></pre>
  
  <p>But why not do this?</p>
  
  <pre><code>class Example:
      def __init__(self,param1,param2):
          self.param1 = param1
          self.param2 = param2
  
      def my_method(self,param1,param2):
          return Example(param1,param2)
  
  example = Example(1,2)
  method = example.my_method(3,4)
  print(method)
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>&lt;__main__.Example object at 0x02EC57D0&gt;
  </code></pre>
  
  <p>It's the same result but it does not come to mind when I could use classmethod</p>