Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82158 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-12-09 10:54 +1100 |
| Last post | 2014-12-09 10:54 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Question on lambdas Chris Angelico <rosuav@gmail.com> - 2014-12-09 10:54 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-12-09 10:54 +1100 |
| Subject | Re: Question on lambdas |
| Message-ID | <mailman.16744.1418082867.18130.python-list@python.org> |
On Tue, Dec 9, 2014 at 10:43 AM, memilanuk <memilanuk@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
Back to top | Article view | comp.lang.python
csiph-web