title: Confused about __str__ on list in Python
body: <p>Coming from a Java background, I understand that <code>__str__</code> is something like a Python version of toString (while I do realize that Python is the older language).</p>
  
  <p>So, I have defined a little class along with an <code>__str__</code> method as follows:</p>
  
  <pre><code>class Node:
  
      def __init__(self, id):
          self.id = id
          self.neighbours = []
          self.distance = 0
  
  
      def __str__(self):
          return str(self.id)
  </code></pre>
  
  <p>I then create a few instances of it:</p>
  
  <pre><code>uno = Node(1)    
  due = Node(2)    
  tri = Node(3)    
  qua = Node(4)
  </code></pre>
  
  <p>Now, the expected behaviour when trying to print one of these objects is that it's associated value gets printed. This also happens.</p>
  
  <pre><code>print uno
  </code></pre>
  
  <p>yields</p>
  
  <pre><code>1
  </code></pre>
  
  <p>But when I do the following:</p>
  
  <pre><code>uno.neighbours.append([[due, 4], [tri, 5]])
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>print uno.neighbours
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>[[[&lt;__main__.Node instance at 0x00000000023A6C48&gt;, 4], [&lt;__main__.Node instance at 0x00000000023A6D08&gt;, 5]]]
  </code></pre>
  
  <p>Where I expected</p>
  
  <pre><code>[[2, 4], [3, 5]]
  </code></pre>
  
  <p>What am I missing? And what otherwise cringe-worthy stuff am I doing? :)</p>