Python Anonymous Function

From GM-RKB
Jump to navigation Jump to search

A Python Anonymous Function is a Python function that is an anonymous function.



References

2014

2013

 >>> def f (x): return x**2
 … 
 >>> print f(8)
 64
 >>> g = lambda x: x**2
 ...
 >>> print g(8)
 64
  • http://www.secnetix.de/olli/Python/lambda_functions.hawk
    • As you can see, f() and g() do exactly the same and can be used in the same ways. Note that the lambda definition does not include a "return" statement -- it always contains an expression which is returned. Also note that you can put a lambda definition anywhere a function is expected, and you don't have to assign it to a variable at all.

2012