title: Calling 'del' on a list
body: <pre><code>class ToBeDeleted:
      def __init__(self, value):
          self.value = val
  
      # Whatever...
  
      def __del__(self):
          print self.value
  
  l = [ToBeDeleted(i) for i in range(3)]
  del l
  </code></pre>
  
  <p>This prints <code>2, 1, 0</code>.</p>
  
  <hr>
  
  <ul>
  <li><p>Now, is the order of the deleted elements defined somewhere in specification or is it implementation-specific? <em>(or maybe I don't understand the underlying mechanics)</em></p></li>
  <li><p>Could the output, for example, be <code>0, 1, 2</code>? <em>I realize the <code>2, 1, 0</code> order is probably done to avoid the memory reallocations for the elements while deleting them, but still the question remains.</em></p></li>
  <li><p>And the last one - what's the difference between <code>del l</code> and <code>del l[:]</code> statements?</p></li>
  </ul>