This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abgrover
Recipients
Date 2005-09-20.14:11:21
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
The tutorial for 2.4.1, section 4.6 Defining Functions
states that formal parameters are introduced into the
local symbol table, making all calls call by object
reference.

The footnote points out that this means that changes to
mutable objects will be seen by the caller.  This is
also illustrated in the example involving calling the
list method append.

It would be helpful if the example could point out that
passing a value such as 1 passes an immutable object
(the constant integer value 1), and so it is impossible
to write code such as:

a = 1
def f(val):
  val = val + 1

and expect that after the call a == 2, even though val
== 2.  

My experience is that this is a confusing issue for new
users, who may not understand that val = val + 1 tosses
the object reference value passed, replacing it with a
new local object.  New users tend to see val as a
mutable object, since we just changed the value, didn't
we?  :)
History
Date User Action Args
2008-01-20 09:58:10adminlinkissue1296434 messages
2008-01-20 09:58:10admincreate