Problem with assigning variables of type List
Paul Foley
see at below
Tue Aug 20 04:33:26 EDT 2002
On Tue, 20 Aug 2002 09:27:02 +0200, Max M wrote:
> Paul Foley wrote:
>> On 19 Aug 2002 14:48:34 -0700, Abhishek Roy wrote:
>>> Thank you very much. I had not realized that lists are passed by
>>> reference by default,
>> Good. Because they're not.
> Please elaborate with an example. A statement like that dosn't add much
> to the discussion.
> But I don't think we have the same definition of "by reference" and "by
> value"!
> l1 = l2 = [1,2]
> l1.append(3)
> print l2
>>>> [1, 2, 3]
> That is "by reference" in my book.
Try this:
>>> def reftest(x):
... x = [42]
...
>>> y = [1,2,3]
>>> reftest(y)
>>> y
[1, 2, 3]
if it were passed by reference, you'd see [42] on the last line.
--
Just because we Lisp programmers are better than everyone else is no
excuse for us to be arrogant. -- Erann Gat
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))
More information about the Python-list
mailing list