"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Sun, 24 Feb 2008 21:13:08 -0500, Terry Reedy wrote: | | > | I even use "named anonymous functions" *cough* by assigning lambda | | > functions to names: | > | | > | foo = lambda x: x+1 | > | > Even though I consider the above to be clearly inferior to | > | > def foo(x): return x+1 | > | > since the latter names the function 'foo' instead of the generic | > '<lambda>'. | | Absolutely. If foo() was a function that the user would see, I would | certainly use the def form to create it. | | But in a situation like this: | | | def parrot(x, y, z, func=None): | if func is None: | func = lambda x: x+1 | return func(x+y+z)
Since functions are constants with respect to code attribute, you might as well condense that to def parrot(x,y,z, func = lambda xyz: xyz+1): return func(x+y+z) Then you can claim some actual space saving. | I don't see any advantage to writing it as: | | def parrot(x, y, z, func=None): | if func is None: | def func(x): return x+1 | return func(x+y+z) Good habit? Don't mislead the newbies ;-? tjr -- http://mail.python.org/mailman/listinfo/python-list