On 7/22/14 3:04 PM, fl wrote:
Hi,
I learn Python function call on tutorial. There is a link on this subject.
http://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/

Although it explains clearly, the figure makes me puzzled.

""Python is different. As we know, in Python, "Object references are passed by
value".

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, it shows that the result is [0, 1]  (Am I right on the figure?)


This is a topic that often confuses people new to Python. The article you linked to seems very confusing to me. My own take on how to explain it is here: http://nedbatchelder.com/text/names.html


When I enter the command lines on my computer:
list=[0]
append(list)
print(list)
[0]

How to understand my result and that figure?

You should have gotten [0, 1], you must have different code than was shown in the article. I recommend putting the code into a .py file, and running it all at once. Then if it doesn't do what you expect, you can show the entire .py file when asking for help.




Thanks,



--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to