List unchanged in function--why?

Chris bit_bucket5 at hotmail.com
Mon Feb 18 17:38:13 CET 2002


This must have something to do with references etc, but I'm not sure
what's going on.

def changeList(theList):
  theList = ['a']

aList = ['x', 'y']
print aList
changeList(aList)
print aList


Running the above results in

['x', 'y']
['x', 'y']

Can someone explain?  I was expecting the second line printed to be
['a']

Thanks,
Chris



More information about the Python-list mailing list