title: Python List & for-each access (Find/Replace in built-in list)
body: <p>I originally thought Python was a pure pass-by-reference language.</p>
  
  <p>Coming from C/C++ I can't help but think about memory management, and it's hard to put it out of my head.  So I'm trying to think of it from a Java perspective and think of everything but primitives as a pass by reference.</p>
  
  <p>Problem: I have a list, containing a bunch of instances of a user defined class.</p>
  
  <p>If I use the for-each syntax, ie.:</p>
  
  <pre><code>for member in my_list:
      print(member.str);
  </code></pre>
  
  <p>Is <code>member</code> the equivalent of an actual reference to the object?</p>
  
  <p>Is it the equivalent of doing:</p>
  
  <pre><code>i = 0
  while i &lt; len(my_list):
      print(my_list[i])
      i += 1
  </code></pre>
  
  <p>I think it's NOT, because when I'm looking to do a replace, it doesn't work, that is, this doesn't work:</p>
  
  <pre><code>for member in my_list:
      if member == some_other_obj:
          member = some_other_obj
  </code></pre>
  
  <p>A simple find and replace in a list.  Can that be done in a for-each loop, if so, how?  Else, do I simply have to use the random access syntax (square brackets), or will NEITHER work and I need to remove the entry, and insert a new one?  I.e.:</p>
  
  <pre><code>i = 0
  for member in my_list:
     if member == some_other_obj:
        my_list.remove(i)
        my_list.insert(i, member)
     i += 1
  </code></pre>