Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82177 > unrolled thread

Re: Question on lambdas

Started byBen Finney <ben+python@benfinney.id.au>
First post2014-12-09 16:30 +1100
Last post2014-12-09 16:30 +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.


Contents

  Re: Question on lambdas Ben Finney <ben+python@benfinney.id.au> - 2014-12-09 16:30 +1100

#82177 — Re: Question on lambdas

FromBen Finney <ben+python@benfinney.id.au>
Date2014-12-09 16:30 +1100
SubjectRe: Question on lambdas
Message-ID<mailman.16760.1418103009.18130.python-list@python.org>
memilanuk <memilanuk@gmail.com> writes:

> ...
> lambda: update_label2('A', 100)
>
> would this work the same?

(I don't know what you mean here by “the same”; the same as what?)

The above creates a new function, which expects no parameters (because
there are no parameters before its ‘:’).

The function, when called, will return the value of the expression
‘update_label2('A', 100)’.

> It looks as though it'd be passing the same two parameters to the same
> function...

Yes, it looks that way, and that's what it does. The parameters are
fixed in the expression and will be the same each time the new function
is called.

> lambda: 'A', 100: update_label2()

This is a syntax error.

Have you tried experimenting with these? Carefully read the reference
material on the ‘lambda’ syntax, and create some functions and
experiment with them.

-- 
 \     “Not to be absolutely certain is, I think, one of the essential |
  `\                         things in rationality.” —Bertrand Russell |
_o__)                                                                  |
Ben Finney

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web