title: Looping over a list of objects in Python, reference/assignment works unexpectedly
body: <p>I have some code that does what I need it to, but I expect it not to. I expect it should be broken, but it works.</p>
  
  <p>I am trying to keep find and keep track of a the best* instance from a list of objects, and am assigning the variable <code>best_sucessor_state</code> to the variable <code>successor_state</code> each time I find a <code>successor_state</code> which is better* than the current <code>best_sucessor_state</code>. </p>
  
  <p>With each loop of the for loop, the variable <code>successor_state</code> is assigned(?) to a new <code>state</code> instance from the list of <code>state</code> objects generated by <code>current_state.successor_states()</code></p>
  
  <p>Since I am assigning(?) <code>best_sucessor_state</code> to the variable <code>successor_state</code>, I do not understand why the underlying state to which <code>best_successor_state</code> is assigned(?) does not update each time the for-loop loops and the variable <code>successor state</code> is assigned(?) to a new <code>state</code> from the <code>current_state.successor_states()</code> list.</p>
  
  <p>If someone could explain the following I would be very grateful:</p>
  
  <ol>
  <li>Why this is the case?</li>
  <li>If I wanted to break my code and have <code>best_successor_state</code> stay up to date with the changes of <code>successor_state</code> as the loop loops, how could I do this?</li>
  <li>What is the accurate language ("assignment/referencing", "variable/label/name") that I should be using?</li>
  </ol>
  
  <p>*<strong>best</strong>: The <code>state</code> class has a method to calculate the value, which is called <code>objective_function</code>, the lower the better</p>
  
  <p>Here's the code, many thanks:</p>
  
  <pre><code>def steepest_ascent_HCS(initial_state, objective_function):
  
      current_state = initial_state
  
      while True:
          current_state_value = objective_function(current_state)
          best_successor_state_value = float('inf')
  
          for successor_state in current_state.successor_states():
              successor_state_value = objective_function(successor_state)
  
              if successor_state_value &lt; best_successor_state_value:
                  best_successor_state = successor_state
                  best_successor_state_value = successor_state_value
  
          if best_successor_state_value &gt;= current_state_value:
                  return current_state, current_state_value
  
          current_state = best_successor_state
  </code></pre>