assigning values in python and perl

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Jan 16 23:20:14 EST 2008


On Thu, 17 Jan 2008 11:40:59 +0800, J. Peng wrote:

> May I ask, python's pass-by-reference is passing the object's reference
> to functions, but perl, or C's pass-by-reference is passing the variable
> itself's reference to functions. So althought they're all called
> pass-by-reference,but will get different results.Is it?

Python is not call by reference.

Any book or person that says it is, is wrong to do so.

Python's function call semantics are not the same as C, or Perl, or 
Pascal. They are, however, similar to those of Lisp, Scheme, Emerald and 
especially CLU. It is neither pass by reference, nor pass by value.

Java also uses similar call-by-object (sometimes call-by-sharing) 
semantics, and just like Python, Java developers tie themselves in knots 
by using misleading names for it:

http://codertricks.strainu.ro/java/2007/05/02/why-java-sends-parameters-
by-value/

and 

http://codertricks.strainu.ro/java/2007/06/15/call-by-sharing/


Did you read the links I sent you yesterday, especially the second one?

http://effbot.org/zone/python-objects.htm
http://effbot.org/zone/call-by-object.htm



-- 
Steven



More information about the Python-list mailing list