Question about Pass-by-object-reference?
rxjwg98 at gmail.com
Tue Jul 22 21:34:51 CEST 2014
On Tuesday, July 22, 2014 3:04:09 PM UTC-4, fl wrote:
Excuse me. I find that the OP misses some info. I rewrite it again:
I learn Python function call on tutorial. There is a link on this subject.
Although it explains clearly, the figure makes me puzzled.
""Python is different. As we know, in Python, "Object references are passed by
A function receives a reference to (and will access) the same object in memory as used by the caller. However, it does not receive the box that the caller is
storing this object in; as in pass-by-value, the function provides its own box
and creates a new variable for itself. Let's try appending again:""
On the figure, I understand the figure about append function. Here is the lines:
When I enter the command lines on my computer:
>>> def append(list):
But I don't understand the reassign function result:
>>> def reassign(list):
>>> print list
1. From the tutorial explanation, both function append and reassign use
pass-by-object-reference. Is it right?
2. The tutorial says: "The caller doesn't care if you reassign the function's
box. Different boxes, same content." about the reassign function. I don't
understand "Different boxes, same content". It uses different boxes (I agree).
But the results are different for the caller () and the function reassign
What is wrong with my understanding?
Thanks a lot,
More information about the Python-list