title: Why can't I change attribute of a class in Python
body: <p>We say <code>classes</code> are mutable in Python which means you can using references we can change the values that will be reflected in object. For example,</p>
  
  <pre><code>&gt;&gt;&gt; A = [1, 2, 3]
  &gt;&gt;&gt; B = A
  &gt;&gt;&gt; B[2] = 5
  &gt;&gt;&gt; A
  [1, 2, 5]
  </code></pre>
  
  <p>Here I can change the values of <code>A</code> object using <code>B</code> because <code>list</code> is a mutable type. My question is why can't I change the attributes of a class below using same concept:</p>
  
  <pre><code>class C:
  
      apple = 2
  
      def __init__(self):
          self.dangerous = 2
  
  D = C # D is pointing to same class C
  
  D().dangerous = 5 # changing the value of class attribute D
  
  D().apple = 3 # changing the value of apple here
  
  print D().apple
  
  print D().dangerous
  
  OUTPUT:
  2
  2
  </code></pre>
  
  <p>Could anyone explain why the output is <code>2</code> and <code>2</code> but not <code>3</code> and <code>5</code> since we are saying that the class is a <code>mutable</code> type.</p>
  
  <p>UPDATE : Referring to the answer by @zxq9, if you see the below diagram when do <code>D=C</code>, <code>D</code> is actually pointing to the same class rather a new object as you have described. Could you explain this:</p>
  
  <p><a href="https://i.stack.imgur.com/fzG2z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fzG2z.png" alt="enter image description here"></a></p>