Your code:
number = ['0','1','2']
def foo(psswd):
psswd = number[:]
if __name__ == '__main__':
psswd = []
foo(psswd)
print psswd
psswd = number[:]
rebinds local variable psswd
with a new list.
I.e., when you do foo(psswd)
, function foo
is called, and local variable passwd
inside it is created which points to the global list under the same name.
When you do psswd = <something>
inside foo
function, this <something>
is created/got and local name psswd
is made to point to it. Global variable psswd
still points to the old value.
If you want to change the object itself, not the local name, you must use this object's methods. psswd[:] = <smething>
actually calls psswd.__setitem__
method, thus the object which is referenced by local name psswd
is modified.