Question on lambdas
Chris Angelico
rosuav at gmail.com
Mon Dec 8 18:54:24 EST 2014
On Tue, Dec 9, 2014 at 10:43 AM, memilanuk <memilanuk at gmail.com> wrote:
> What I'm having trouble finding a concrete answer to is the difference
> between:
>
> lambda: some_func
>
> lambda e: some_func
These two are quite simple. (In each case, it's an expression, not a
function, for what it's worth.) They're (roughly) equivalent to these
functions:
def anonymous():
return some_func
def anonymous(e):
return some_func
In other words, the second one takes an argument, the first doesn't.
> lambda e=e: some_func
I'm not sure what this one ought to be; do you have an example? If the
"e=" part comes before the "lambda", though, then it's simply a named
argument getting a lambda function bound to it. In your example above,
this:
Radiobutton(... command=lambda: update_label2('A', 100))
is equivalent to this:
def anonymous():
return update_label2('A', 100)
RadioButton(... command=anonymous)
It's that simple.
ChrisA
More information about the Python-list
mailing list