Newbie Q: var params

Alex Martelli aleaxit at yahoo.com
Wed Apr 11 06:16:31 EDT 2001


"zzzzz" <zzizz_ at notmail.com> wrote in message
news:bnj7dto6gf5859sd7sl4v00ch6ue7ejagl at 4ax.com...
> Hi all,
>
> I (possibly incorrectly) thought that parameters passed in functions
> were modifiable by default in Python, here is some code that I tested

A function is passed (references to) objects that may be
either modifiable (e.g., lists) or not (e.g., tuples).

> It looks like "parameter=[2,4,6,8]" creates a new local variable that

No, it just *RE-BINDS* your local variable 'parameter' so it
now refers to this new list object -- which has no effect on
whatever 'parameter' was previously bound to, and has
nothing to do with modifiable objects.

Assuming 'parameter' is currently bound to a list (e.g., that
a list object was passed as the corresponding actual parameter),
you can perform modifying-operations on the list you were passed
in; e.g., the modification "substitute all of the list contents":
    parameter[:] = [2, 4, 6, 8]


Alex






More information about the Python-list mailing list