"Updating" lambda functions

Terry Reedy tjreedy at udel.edu
Fri Sep 17 03:47:07 CEST 2004


"Oliver Fromme" <olli at haluter.fromme.com> wrote in message 
news:2qtl0oF139gn6U1 at uni-berlin.de...
>        fu = lambda x: x
>        fu = lambda x: fu(x) + 17
etc

I am curious if there is any reason other that habit carried over from 
other languages to not write the above as

def fu(x): return x
def fu(x): return fu(x) + 17
etc

Granted, the latter takes 2 more keystrokes, but the resulting object gets 
a proper .name attribute.  And, of course, the def form is required for a 
multiline body anyway.

(Note: I am not asking about the use of lambda *within* an expression or as 
a return value, but only the immediate name-binding of the supposedly 
anonymous function where one does not want anonymity.)

Terry J. Reedy






More information about the Python-list mailing list