[Tutor] dictionaries, objects and scoping...
alan.gauld at btinternet.com
Tue Jan 22 09:27:57 CET 2008
"John Morris" <jrmorrisnc at gmail.com> wrote
> So this seems like it will make scope/namespaces a bit
namespaces in python are literally that, they are spaces
where *names* are visible. Objects are something else
entirely and assignment only pins a name to an object.
So in Python namespaces contriol where you can use a
name, not where you can use an object.
def f(y): return y+1
x = 66
y is a name that is only visible inside f.
66 is a number object associated with x
and passed into f where it is associated
with y. The number object inside f is the
same object outside f only the name has
changed.The return value is a new number
object (67 in this case).
Author of the Learn to Program web site
More information about the Tutor