title: Difference between Class variables and Instance variables
body: <p>I have already read many answers here on Stack Exchange like <a href="https://stackoverflow.com/questions/475871/python-why-use-self-in-a-class">Python - why use &quot;self&quot; in a class?</a>
  After reading these answers, I understand that instance variables are unique to each instance of the class while class variables are shared across all instances.</p>
  <p>While playing around, I found that this code which gives the output <code>[1]</code>:</p>
  <pre><code>class A:
      x = []
      def add(self):
          self.x.append(1)
  
  x = A()
  y = A()
  x.add()
  
  print &quot;Y's x: &quot;, y.x
  </code></pre>
  <p>However, this code gives <code>10</code> as the output, when in my opinion it should be <code>11</code>:</p>
  <pre><code>class A:
      x = 10
      def add(self):
          self.x += 1
  
  x = A()
  y = A()
  x.add()
  
  print &quot;Y's x: &quot;, y.x
  </code></pre>
  <p>Why <code>A</code> class variable is not updated when I run <code>x.add()</code>? I am not very experienced in programming, so please excuse me.</p>