Python pass list as function parameter
number = ['0','1','2'] def foo(psswd): psswd = number[:] if __name__ == '__main__': psswd =  foo(psswd) print psswd
psswd = number[:]
restores a local variable
with a new list.
Ie, when you execute
, a function is called
and inside of it a local variable is created
that points to a global list of the same name.
When you execute
psswd = <something>
, this one
is created / retrieved and the local name
is made to point to it. The global variable
still points to the old value.
If you want to change the object itself and not the local name, you must use these methods of the object.
psswd[:] = <smething>
is actually calling the method
, so the object being referenced by the local name
source to share