On Jan 16, 7:59 am, "J. Peng" <[EMAIL PROTECTED]> wrote: > On Jan 16, 2008 1:45 PM, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > > > On Wed, 16 Jan 2008 11:09:09 +0800, "J. Peng" <[EMAIL PROTECTED]> > > > 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!
'a' was not modified because you locally assigned a new object with 'x=[4,5,6]'. If you want the new list you created you will have to return it. You can see how you modify it if you were to use 'x.append()' or 'x.extend()' for eg. -- http://mail.python.org/mailman/listinfo/python-list