2015年9月8日 星期二

[RR Python] lambda function

a lambda function is a function that takes any number of arguments (including optional arguments)
and returns the value of a single expression. lambda functions can not contain commands, and
they can not contain more than one expression.

there are no parentheses around the argument list, and the return keyword is missing (it is implied, since the entire function can only be one expression).

>>>(lambda x: x*2)(3)
6

an other interesting lambda

Why do lambdas defined in a loop with different values all return the same result?



1 則留言: