Scope of instantiated class

Stefan Schwarzer sschwarzer at sschwarzer.net
Mon Jul 22 13:36:45 EDT 2002


Hello Peter

Peter Hansen wrote:
> When you create an object ("instantiate a class") you
> must bind it to a name ("assign it to a variable").  If

What about

L = [1, [2, 3]]

? The object [2, 3] can be accessed but it doesn't have a name.

Another example is the use of lambda functions like this:

translations = { 'dos_to_unix': lambda s: s.replace('\r', ''),
                  'unix_to_dos': lambda s: s.replace('\n', '\r\n') }

Here, the lambdas can be accessed via the dictionary keys but are not bound
to a name.

Stefan




More information about the Python-list mailing list