Let's Talk About Lambda Functions!

Steve Holden sholden at holdenweb.com
Sat Jul 27 00:19:03 EDT 2002


"John Roth" <johnroth at ameritech.net> wrote in message
news:uk3abpr4treeb9 at news.supernews.com...
>
> "Britt A. Green" <python at experimentzero.org> wrote in message
> news:mailman.1027705851.8443.python-list at python.org...
> > So I know what lambda functions are, their syntax and how they're
> used.
> > However I'm not sure *why* one would use a lambda function. What's the
> > advantage that they offer over a regular function?
>
> They let you put short, one-time functions inline. In some
> environments (Tkinter comes immediately to mind) there
> are lots of places where short, one-line functions are useful.
> Putting a short, one-time function inline aids readability,
> (at least for people who regard lambdas as readable.)
>
> IMO, if the function is of any significant length, or if it
> duplicates functionality from elsewhere, it should be
> named and written separately.
>

And let us not forget that those who hate naming one-off functions can reuse
the names if they want.

def a(x):
    print x
def a(y):
    print y*y

is perfectly legal Python.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list