A question about reference in Python.
joe at strout.net
Tue Dec 9 05:30:00 CET 2008
On Dec 8, 2008, at 7:43 PM, Steven D'Aprano wrote:
> On Mon, 08 Dec 2008 08:18:27 -0700, Joe Strout wrote:
>> On Dec 7, 2008, at 10:26 PM, Group wrote:
>>> Now, I want to write a Red-Black Tree, and a List structure. In C/C
>>> + +,
>>> I can
>>> use pointers to refer to children notes (or next notes). But, in
>>> Python, how
>>> can I do it? Except the sequence, I know not any way.
>> Any variable in Python is a reference
> Except that they don't behave like references in languages that have
> explicit reference parameters.
I didn't say anything about reference parameters (by which I believe
you mean parameters passed by reference). I say a variable in Python
IS a reference. And it is *exactly* like a reference parameter in any
other modern OOP language, as I've clearly shown (http://www.strout.net/info/coding/valref/
That page also explains that Python's references are always passed by
value; Python doesn't have a pass-by-reference mechanism, unlike (say)
RB, C++, or .NET.
This stuff really isn't that hard.
> Did you not see the thread asking how to create reference parameters
> Python? Subject "var or inout parm?". I noticed you were conspicuous
> your absence in that little discussion.
No, sorry, I missed that one. The volume of this group (plus the
several other Python lists I subscribe to) requires me to skim a lot,
and often choose not to read a thread at all.
In this case, the subject caught my attention, and I saw that I could
help clear up some confusion. Now that I've done that, I'll probably
cease to read this thread any further, since as you say, we've been
over this to death. Go ahead and try to confuse him if you insist.
Hopefully he'll ignore that and see that Python is simple, and
identical in its semantics to the languages he already knows.
More information about the Python-list