no pass-values calling?

J. Peng peng.kyo at gmail.com
Wed Jan 16 00:59:03 EST 2008


On Jan 16, 2008 1:45 PM, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Wed, 16 Jan 2008 11:09:09 +0800, "J. Peng" <peng.kyo at gmail.com>
>
> alist = []
> anint = 2
> astr = "Touch me"
>
> dummy(alist, anint, astr)
>
>         "dummy" can only modify the contents of the first argument -- the
> integer and string can not be mutated.

Hi,

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]
...
>>> mytest(a)
>>> a
[1, 2, 3]

As you see, a was not modified.
Thanks!



More information about the Python-list mailing list