title: In a loop in Python, I assign a new instance of a class to the same variable, but it keeps pointing to the old instance?
body: <p>I created the following class that represents a chest where toys (numbers) can be stored:</p>
  
  <pre><code>class Chest:
  
    toys = []
  
    def __init__(self):
      return
  
    def add(self, num):
      self.toys.append(num)
      return
  </code></pre>
  
  <p>The main code that uses this class is as follows:</p>
  
  <pre><code>room_of_chests = []
  
  for i in range(3):
  
    print "Chest", i
    temp = Chest()
  
    print "Number of toys in the chest:", len(temp.toys)
  
    for j in range(5):
      temp.add(j)
  
    print "Number of toys in the chest:", len(temp.toys)
    print ""
  
    room_of_chests.append(temp)
  </code></pre>
  
  <p>So, for each iteration of i, I create a new <em>Chest</em> and make the variable <em>temp</em> point to it (correct?). So, in theory, in each iteration, temp would start with an empty chest and end with a chest with 5 toys (correct?).</p>
  
  <p>Therefore, the output I am expecting is:</p>
  
  <pre><code>Chest 0
  Number of toys in the chest: 0
  Number of toys in the chest: 5
  
  Chest 1
  Number of toys in the chest: 0
  Number of toys in the chest: 5
  
  Chest 2
  Number of toys in the chest: 0
  Number of toys in the chest: 5
  </code></pre>
  
  <p>However, what I am actually getting is:</p>
  
  <pre><code>Chest 0
  Number of toys in the chest: 0
  Number of toys in the chest: 5
  
  Chest 1
  Number of toys in the chest: 5
  Number of toys in the chest: 10
  
  Chest 2
  Number of toys in the chest: 10
  Number of toys in the chest: 15
  </code></pre>
  
  <p>What am I doing wrong? Can someone give a quick explanation of how instantiation works in this case? And the rules of variables pointing to objects in Python? Thanks in advance.</p>