The future of Python immutability

Steven D'Aprano steven at
Mon Sep 7 06:27:01 CEST 2009

On Sun, 06 Sep 2009 06:18:23 -0700, Adam Skutt wrote:

> On Sep 5, 7:38 pm, Steven D'Aprano <st... at REMOVE-
>> No. Lambdas are a *syntactical construct*, not an object. You wouldn't
>> talk about "while objects" and "if objects" and "comment objects"
>> *because they're not objects*.
> This rhetoric precludes functions objects as well and is entirely non-
> compelling.

Functions ARE objects in Python. They even inherit from object:

>>> def f():
...     return None
>>> isinstance(f, object)

Just because there is syntax for creating functions (at least two 
different syntax forms actually) doesn't "preclude function objects". 
There is syntax for dicts, and dict objects; syntax for lists, and list 
objects; syntax for strings, and string objects. But there's syntax for 
while loops, and no such thing as a while object.

Lambda expressions are syntax for creating function objects. That's all 
there is to it, end of story.

>> Functions created with def and functions created with lambda are
>> *precisely* the same type of object.
> Which means you have lambda objects.  The fact they're same as any other
> function is irrelevant and not especially interesting.

They're *function* objects, not "lambda" objects:

>>> type(lambda: None)
<type 'function'>

>> There is no such thing as a "lambda
>> object" which is a "special case" of ordinary functions, there are just
>> functions.
> Hey, I was just trying to resolve tjr's view, he seemed to think that
> .__name__ is different is pretty important, and he's the one you should
> take your objections up with, not me.

Nice try but no. It was YOU, not Terry, claiming that lambda's are a 
special kind of object different from ordinary functions.


More information about the Python-list mailing list