En Tue, 28 Oct 2008 01:16:04 -0200, Dale Roberts <[EMAIL PROTECTED]>
escribió:
So, then, what to tell a C++ programmer about how Python passes
arguments? You say: tell them Python only passes by value. I disagree,
because I think that would confuse them. Rather than try to map C++
conventions onto Python, I think it is more useful to just tell them how
it really works. Maybe a few statements like this:
All values in Python are objects, from simple integers up to complex
user-defined classes.
An assignment in Python binds a variable name to an object. The
internal "value" of the variable is the memory address of an object,
and can be seen with id(var), but is rarely needed in practice.
The "value" that gets passed in a Python function call is the address
of an object (the id()).
When making a function call, myfunc(var), the value of id(var) can
never be changed by the function.
Not sure if these are the best. To get into much more detail, you have
to start explaining mutable and immutable objects and such.
I don't think the above explanation is desirable, nor needed. Objects in
Python don't have an "address" - it's just a CPython implementation
detail. The fact that id() returns that address is just an implementation
detail too. The calling mechanism should be explained without refering to
those irrelevant details.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list