"Ajit Deshpande" <aji...@gmail.com> wrote

I am trying to figure out where lambda functions can be useful. Has anyone
used them in real world?

Yers lots of people, all over the place. They are very useful things.

Why would anyone use a one liner anonymous function,

To pass as an argument to another function.
GUI widgets for example frequently take a function as
an argument so that when they are clicked they call
the function. If the function is only doing something
trivial a lambda is better than writing a small function
just to pass to the GUI widget.

Similarly functions like sort() often take functions as
arguments so that you can customise the sort
algorithm. Often these are just one liners defining
how a comparison should work.

lambda comes from the matth/computer science term
lambda calculus and lambdas are at the very core of
theoretical computing. Functional programming is a style
closely aligned to computer science theory and as
such makes much use of lambdas (Lisp does this too).

You can read more on the use of Lambdas and
functional programming in the Functional Programming
topic of my tutorial. You can see lambdas in use in the
GUI topic of my tutor.

HTH,


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


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to