title: How does Python increment list elements?
body: <p>Can someone explain to me why the first code block doesn't change the list, but the second does.</p>
  
  <pre><code>a = [1,2,3]
  for el in a:
      el += 5
  </code></pre>
  
  <p>This leaves <code>a</code> as <code>[1,2,3]</code>. That said if I run</p>
  
  <pre><code>a = [1,2,3]
  for i in range(len(a)):
      a[i] += 5
  </code></pre>
  
  <p>then <code>a = [6,7,8]</code>. My guess is that in the first, when looping over the elements <code>el</code> is a temporary variable, and not actually the thing that references that element in the list. Not sure why incrementing it doesn't effect the list though.</p>