types.FunctionType vs types.LambdaType

Xavier Defrang xavier at perceval.net
Fri Feb 9 04:22:53 EST 2001

Dear fellow Pythoneers,

I was exploring the wonderful world of the Python 
documentation when I saw that the standard library
types module had two distinct function types : 
FunctionType and LambdaType.  Both of these are
references to the type 'function' (see code snippet).  

>>> def f(x):
... 	return x
>>> t1=type(f)
>>> t2=type(lambda x: x)  
>>> t1, t2
(<type 'function'>, <type 'function'>)
>>> import types
>>> types.FunctionType
<type 'function'>
>>> types.LambdaType
<type 'function'>
>>> types.FunctionType == types.LambdaType

I can't figure out the rationale for this LambdaType.
It might even be confusing for people who think they
can make the difference between a "real" function and 
a function created from a lambda expression.

I think that it's fair that no one can tell the 
difference between a "real" function (a 'def' statement)
and a lambda statement but why are there two types ?!?


Xavier Defrang
Perceval R&D Team
xavier at perceval.net

 Perceval Technologies SA/NV  Tel: +32-2-6409194
 Rue Tenbosch, 9              Fax: +32-2-6403154
 B-1000 Brussels         http://www.perceval.net
 BELGIUM                       info at perceval.net

More information about the Python-list mailing list