Pass by reference ?
Greg Ewing
greg at cosc.canterbury.ac.nz
Tue Apr 4 23:20:35 EDT 2000
Nick Maclaren wrote:
>
> Unless I am thoroughly confused, Python uses bog-standard call by
> reference, with the wrinkle that assignment is a rebinding rather
> than a copying operation. AM I confused about that?
The trouble with describing Python parameter passing as
"call by reference" is that that term implies something
like a Pascal VAR parameter, which Python most certainly
does *not* have. That's why Mr. Generowicz got confused -
he thought it meant that a reference to the *variable*
x was being passed.
If I had to pick one of the standard terms, I would describe
Python parameter passing as call-by-value, with the wrinkle
that the value being passed is always a reference to an object.
But I think it's better to avoid using any of the terms
developed for describing parameter passing in Algol-like
languages when explaining Python to a newcomer, because
none of them really fit properly, and further explanation
is needed to avoid confusion. It's better to just give the
full explanation in the first place.
--
Greg Ewing, Computer Science Dept,
+--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg at cosc.canterbury.ac.nz +--------------------------------------+
More information about the Python-list
mailing list