Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Secret Agent Man Solution - Intro to Computer Science

Get Embed Code
6 Languages

Showing Revision 6 created 05/25/2016 by Udacity Robot.

  1. [Narrator] The answer is 8.
  2. Let's try this in the Python interpreter to see why.
  3. These are the first 2 assignments, and after these assignments
  4. we can see that agent has the same value as spy.
  5. Both spy and agent have the value a list containing 3 elements.
  6. The element values are 0, 0, 7, and
  7. they're actually the same list object because both agent and spy refer to that
  8. same list that we created in the first assignment.
  9. This means the value in agent position 2 is the number 7.
  10. When we do the third assignment we're assigning into position 2 of spy
  11. the value at position 2 of agent plus 1.
  12. The value at position 2 of agent is 7, add 1 to that we get 8,
  13. and we put that in position 2 of spy.
  14. Since agent and spy refer to the same object that changes the value of both spy and agent,
  15. and we can see that both agent and spy now contain the value 8, and position 2.