Let's Talk About Lambda Functions!

John Roth johnroth at ameritech.net
Tue Jul 30 11:59:44 EDT 2002


"Daniel Fackrell" <unlearned at DELETETHIS.learn2think.org> wrote in
message news:3d46964b$1_2 at hpb10302.boi.hp.com...
> "John Roth" <johnroth at ameritech.net> wrote in message
> news:ukb31ell2rh643 at news.supernews.com...
>
> <snip>
>
> >     for word in 'fee fie fo fum'.split():
> >         Button(frame, command = def ():
> >                 print word
> >             )
> >
> > This isn't really the world's best example, because IMO, the
> > lambda form is easier to read for something this small. However,
> > it does give the guts of the idea:
>
> <snip>
>
> > 2. The remainder of the syntax exactly models def, including
> > statement indentation within the expression. Notice that the
> > first statement in the anonamous function has to be indented
> > two from the preceeding line, because the continuation of
> > the expression has to still be indented from the line with the
> > 'def', and dedented from the statements.
>
> IIRC, there's no such ting as "indenting two" in Python as the size of
an
> indentation is automatically detected as you go along, making the
following
> indentation style valid (although no one would ever want to do it):
>
> toplevel
>  secondlevel
>                 thirdlevel
>  secondlevel
>     thirdlevel
>      fourthlevel
>  secondlevel
> toplevel

The reason I say "indenting 2" is that you need two
dedents to make it work: one to close the def, which does
not have it's own indent, and one to finish off the expression
in which the def is imbedded.

Does this make it clearer?

John Roth






More information about the Python-list mailing list