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


Groups > comp.lang.python > #82160

Re: Question on lambdas

Date 2014-12-08 15:52 -0800
From Gary Herron <gherron@digipen.edu>
Subject Re: Question on lambdas
References <m65d2m$3pe$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.16746.1418083206.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/08/2014 03:43 PM, memilanuk wrote:
>
> So... I was browsing some questions on reddit, and one of them 
> involved tkinter and lambdas.  Managed to help the person out, but in 
> the process ended up with more questions of my own :/
>
> My basic confusion revolves around this: in one instance I see things 
> like the following:
>
> R1 = tk.Radiobutton(root, text='A', value=100, variable=var,
>                     command=lambda: update_label2('A', 100))
>
> and in another example I see things like this:
>
> class MyText(Text):
>     def __init__(self, master, **kw):
>         apply(Text.__init__, (self, master), kw)
>         self.bind("<Return>", lambda e: "break")
>
>
> What I'm having trouble finding a concrete answer to is the difference 
> between:
>
> lambda: some_func
A function to be called with no parameters

>
> lambda e: some_func
A function to be called with one parameter

>
> lambda e=e: some_func
A function to be called with one or zero parameters.  In the case of a 
call with no parameters, a default value has been supplied.  The e=e may 
be slightly confusing, because 'e' is used in two contexts, one for the 
name of the parameter inside the function, and the other the name of the 
supplied default value (from the outer scope).
>
> Any help would be greatly appreciated.
>
> TIA,
>
> Monte
>

Hope that helps,

Gary Herron


-- 
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question on lambdas Gary Herron <gherron@digipen.edu> - 2014-12-08 15:52 -0800

csiph-web