First page Back Continue Last page Overview Graphics

lambda allows you to create an unnamed

throw-away function.

lambda argument_list: expression

After the keyword lambda follows an

unnamed function.

Before the colon (:) you list the

parameters of the function.

After the colon you formulate

what the function shall

return.

You can assign the

function to a variable to

give it a name. The

following two practices

are identical:

>>> def add42(x):

... return x + 42

...

>>> add42(10)

52

>>> add42 = lambda x : x + 42

>>> add42(10)

52

Operator