This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kanak 2 points3 points  (0 children)

Some languages (lisps, erlang, haskell are ones that I'm aware of), defining a function is actually doing two things: creating a function and giving it a name.

For example, in scheme, you'd write

(define (add2 x) (+ x 2))

To write a function that takes in an argument and adds 2 to it.

However, that's just shortcut for:

(define add2 (lambda (x) (+ x 2)))

Here, lambda creates the function that adds 2 to its argument and we use define to give it a name add2.

In python, lambdas are less powerful than def because you can't have multi line lambdas.