passing by refference

Donn Cave donn at u.washington.edu
Tue May 13 15:59:54 EDT 2003


Quoth Joshua Marshall <joshway_without_spam at myway.com>:
...
| See
|
|   http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?call-by-value
|
| What you describe is call-by-value.  There is an implicit copy of the
| arguments passed to a function, though not a deep-copy.  The values
| that are being copied are often references.

That's a clever analysis - ``the values that are being copied are
often references'', indeed.

The only really 100% answer to this question - does Python pass by
value or by reference - is "No!"  Then one can approach this subject
with a fresh mind unimpeded by the baggage of other programming
languages (and FOLDOC.)

The ``values that are being copied'' are _always_ references.
The result of an operation on this reference from within the function,
is identical to the same operation outside it - if I pass a parameter
"x" and then assign to it "x = 5", in either case, x is a reference
and I replace the original "x" with a new one.  The only difference
is that the function and its caller bind to different namespaces.
Operations on the object - methods, indexing etc - apply to the original
object, namespace binding applies to the current namespace.
Is it call by reference, or call by value?  No!

	Donn Cave, donn at u.washington.edu





More information about the Python-list mailing list