Binding a variable?
kent37 at tds.net
Fri Oct 21 19:28:46 CEST 2005
Paul Dale wrote:
> Hi everyone,
> Is it possible to bind a list member or variable to a variable such that
No, Python variables don't work that way.
> temp = 5
The name 'temp' is now bound to the integer 5. Think of temp as a pointer to an integer object with value 5.
> list = [ temp ]
the name 'list' is bound to a list whose only member is a reference to the integer 5
> temp == 6
Ok now temp is bound to a new integer, but the list hasn't changed - it's member is still a reference to 5
> would show
> list = [ 6 ]
You have to put a mutable object into the list - something whose state you can change. For example this works, because temp and lst are references to the same mutable (changeable) list:
>>> temp = 
>>> lst = [temp]
>>> temp = 5
More information about the Python-list