Next / Previous / Contents / TCC Help System / NM Tech homepage

24.1. A function's local namespace

Any name that appears in a function's argument list, or any name that is set to a value anywhere in the function, is said to be local to the function. If a local name is the same as a name from outside the function (a so-called global name), references to that name inside the function will refer to the local name, and the global name will be unaffected. Here is an example:

>>> x = 'lobster'
>>> y = 'Thermidor'
>>> def f(x):
...     y = 'crevettes'
...     print x, y
... 
>>> f('spam')
spam crevettes
>>> print x, y
lobster Thermidor

Keyword parameters have a special characteristic: their names are local to the function, but they are also used to match keyword arguments when the function is called.