[BangPypers] diffrerence between lambda function and ordinary one

Anand Chitipothu anandology at gmail.com
Fri Aug 6 16:34:04 CEST 2010


2010/8/6 Rahul R <rahul8590 at gmail.com>:
> i was writing some basic code . for understanding lambda functions , but
> couldnt understand the difference between a lambda function and an ordinary
> function.
>
> for example
>
>>>>def f (x): return x**2
> ...
>>>> print f(8)
>>>> 64
>>>> g = lambda x: x**2
>>>>
>>>> print g(8)
>>>> 64
>
> wats a need for using lambda functions ..?

Lambda functions are expressions. You can define a lambda function
inside a function call or a dictionary definition, which is not
possible with regular functions. For example:

d.sort(key=lambda x: x.lower())

functions = {
    "lower": lambda k: k.lower(),
    "upper": lambda k: k.upper()
}

Anand


More information about the BangPypers mailing list