Declaring A Function Argument As Global?

Tim Daneliuk tundra at tundraware.com
Thu Jan 16 20:30:07 CET 2003


Skip Montanaro wrote:
>     >> def lhandler(list):
>     >>     list[:] = list[1:]
> 
>     Tim> 'Works like a charm.  But why?
> 
> list[:] on the left-hand side of an assignment assigns to the entire list.
> It's effectively 
> 
>     list[0:len(list)] = rhs

The slicing part I understand well.  What I do not grasp is why using
this construct on the lhs gives you access to the actual list
in question, but list = list[1:] refers to the local variable (formal
parameter) 'list'.  It is the semantics of scope that is confusing me
here, not the list operation...

Thanks,
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com





More information about the Python-list mailing list