Python immutable object from within function
<p>I asked a previous question on stackoverflow here: <a href="http://stackoverflow.com/questions/5653150/python-immutable-types-in-function-calls">Python immutable types in function calls</a> </p>

<p>which made it clear that only references to immutable objects are passed to functions, and so passing a tuple to a function does <em>not</em> result in a full memory copy of that object.</p>

<p>However, according to: <a href="http://www.testingreflections.com/node/view/5126" rel="nofollow">http://www.testingreflections.com/node/view/5126</a> </p>

<blockquote>
  <p>"Some objects, like strings, tuples,
  and numbers, are immutable. <em>Altering</em>
  them inside a function/method will
  create a new instance and the original
  instance outside the function/method
  is not changed."</p>
</blockquote>

<p>I wrote some test code, where an immutable object is passed to a function. As expected, I can modify the object via the parameter-name/reference defined as part of the function header, and all changes only persist within the called function, leaving the original object outside of the function untouched.</p>

<p>So my question is:</p>

<p>Is the new instance created <em>only when an attempt is made to alter/modify</em> the object passed in? I'm guessing that if the object is not changed, a reference to it is all that is required. <strong>More importantly, if it does create a copy upon attempted modification, how does python manage the memory? With a zero-copy/copy-on-write, or does it create a complete replicated object (with the whole object's size reserved in memory) visible only within the called function?</strong></p>
