Dennis Lee Bieber
1/16/2008 7:03:00 AM
On Wed, 16 Jan 2008 13:59:03 +0800, "J. Peng" <peng.kyo@gmail.com>
declaimed the following in comp.lang.python:
> How to modify the array passed to the function? I tried something like this:
>
> >>> a
> [1, 2, 3]
> >>> def mytest(x):
> ... x=[4,5,6]
x is unqualified (in my terms), so you have just disconnected it
from the original argument and connected it to [4,5,6]
But try
x[1] = [4,5,6]
or
x[:] = [4,5,6]
or
x.append([4,5,6])
or
x.extend([4,5,6])
All of these are qualified "x", meaning "go inside of the object
that 'x' is connected to, and modify the insides}
But note that you can not do this if you pass a string, tuple, or
number -- those are not mutable (while string and tuple can be indexed
to retrieve parts, you can not change parts of them).
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/