Simulating multi-dim array problem - OR - reference confusions
holger krekel
pyth at devel.trillke.net
Wed Apr 17 12:09:58 EDT 2002
> > means that the "name 'b' is bound to 'a[0]'". Internally
> > the reference count of the object a[0] is incremented.
> >
> Well, newbies might avoid mis-perceptions by reading the Python as "name 'b'
> is bound to the object currently bound to 'a[0]'", to avoid any belief that
> anything in a changes as a result of the assignment. In strict terms, a[0]
> doesn't *have* a reference count, as far as I can tell without reading the
> interpreter code, though both a and the object bound to a[0] will have a
> reference count.
ok, so
- 'a' is a name bound to a list object.
- 'b=a[0]' binds 'b' to the object that 'a[0]' returns
(because 'a[0]' is actually a method-call to the list object
returning (a reference to) the first object of the list)
No matter how the reference counts actually work,
'b' is a name. And this name is bound to an object.
by issueing 'b=...' you don't change this object but just the
binding.
The best way to explore this is the prompt. by issueing
>>> locals()
you get the local name bindings. I must say that i
*extremly* appreciate that for all variables,
modules, packages, classes, functions etc ... you have
means of binding a name to these objects.
sorry if this was redundant and everyone knew this :-)
holger
More information about the Python-list
mailing list