title: How does @staticmethod and @classmethod act on the variable in python?
body: <p>I wrote a simple program.</p>
  
  <pre><code>class Sample:
  
      num =45
  
      def __init__(self):
          print('Inside constructor')
  
      @classmethod
      def modifyUsingClassMethod(cls):
          cls.num = cls.num + 45
  
      @staticmethod
      def modifyUsingStaticMethod():
          Sample.num = Sample.num+5
  
  s1 = Sample()
  s2 = Sample()
  
  s1.modifyUsingClassMethod()
  print(s1.num, s2.num)
  
  s1.num = s1.num + 5
  print(s1.num)
  
  s1.modifyUsingClassMethod()
  print(s1.num, s2.num)
  
  s1.modifyUsingStaticMethod()
  print(s1.num, s2.num)
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Inside constructor
  Inside constructor
  90 90
  95
  95 135
  95 140
  </code></pre>
  
  <p>Can anyone explain how and why the <code>@staticmethod</code> and <code>@classmethod</code> are acting on the variable 'num'?. Why does the output shows <code>95,135</code> even after I changed the value of num using s1 instance using <code>modifyUsingClassMethod()</code> and why not it is updating in both cases using <code>@staticmethod</code> and <code>@classmethod</code>?</p>
  
  <p>I guess when I am referring to the variable <code>num</code> using class object then python is treating the variable <code>num</code> as an instance variable but when I change the variable <code>num</code> using Class name then the value is not updating in the <code>s1</code> but in <code>s2</code>. I am highly confused how <code>@classmethod</code> and <code>@staticmethod</code> works.</p>