Python execution speed

Sandy Norton sandskyfly at hotmail.com
Tue Nov 20 15:36:50 EST 2001


> > Excuse my curiosity but what's quirky about 'def function(): return 1'
and
> > 'function =
> > lambda: 1'?
>
> (I'm posting to the newsgroup as well, didn't notice you posted to
>  both the newsgroup and me.)
>
> Curiosity is good.  :-)
>
> In Lisp, functions can be built this way:
>
>   cl-user(3): (defun multiply (argument) (* argument argument))
>   multiply
>   cl-user(4): (multiply 3)
>   9
>   cl-user(5):
>
> Where the last evaluated value is returned.
>
> In Python, there is:
>
>   def multiply(argument):
>       return argument * argument
>
> Or (using anonymous functions):
>
>   multiply = lambda argument: argument * argument
>
> Where the lambda has the implicit return-of-last-expression (no return
> needed), while functions do not.
>
> Helpful?

Yup. Thanks. Bases on your post, I'm guessing that lambda functions are more
like Lisp whereas regular python functions are more like C functions (i.e.
they need an explicit return). Well, I'm sure we can all live with this
'quirkiness' (-:

Sandy





More information about the Python-list mailing list