[Tutor] lambda in python

Alan Gauld alan.gauld at btinternet.com
Sat Nov 27 11:03:35 CET 2010


"john tsolox" <tsolox at gmail.com> wrote 

> seeing various examples of lambda in python being ALL one-liners. 
> These one-liners inside a lambda seems not to have the
> full permissible use of the full power of python language 
> (if,for,while). Is this correct?

The lambda expression was introduced into Python by popular demand 
to further support the functional style of programming. Functional 
programming does not encourage the use of state and so lambda 
was constrained to be a pure expression. For practical purposes
this is a slight inconvenience and full function code block 
syntax - ala Ruby - would be nice, but for most of it's intended 
uses lambda expressions are adequate. You can always define 
a named function within the using scope if you need more.

IMO. Rather than seeing lambda increased in power we are frankly 
more likely to see lambda removed from the language in some 
far future incarnation. This has been seriously discussed several 
times on the main Python newsgroup.


See the functional programming topic in my tutorial for more 
info on lambda and Python's FP support as a whole.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list