Question on lambdas
Gary Herron
gherron at digipen.edu
Mon Dec 8 18:52:11 EST 2014
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
More information about the Python-list
mailing list