Declaring A Function Argument As Global?

Eddie Corns eddie at holyrood.ed.ac.uk
Fri Jan 17 12:52:07 EST 2003


Tim Daneliuk <tundra at tundraware.com> writes:

>Skip Montanaro wrote:
>> I believe this should work
>> 
>>     def lhandler(list):
>>         list[:] = list[1:]
>> 
>> Skip
>> 

>'Works like a charm.  But why?  I thought list[:] merely makes a copy of
>something - obviously there is more to the story if it is on the LHS.
>'Care to explain the semantics here?

I think the answer you're looking for is that the contents of the two
variables are 'shared'.

>>> a=[1,2,3]
>>> b=a
>>> b[:] = [9,8,7]
>>> a
[9, 8, 7]

Eddie




More information about the Python-list mailing list