함수 포인터 같기도 한데 LISP에서 따왔다고도 하는데 먼소리인지 안드로메다로.
Python supports the creation of anonymous functions
(i.e. functions that are not bound to a name) at
runtime, using a construct called "lambda".>>> def f (x): return x**2 ...
>>> print f(8)
>>>
>>> g = lambda x: x**2 >>>
>>> print g(8)
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.
[링크 : http://www.secnetix.de/olli/Python/lambda_functions.hawk] |
4.7.5. Lambda Forms¶By popular demand, a few features commonly found in functional programming languages like Lisp have been added to Python. With the lambda keyword, small anonymous functions can be created. Here’s a function that returns the sum of its two arguments: lambda a, b: a+b. Lambda forms can be used wherever function objects are required. They are syntactically restricted to a single expression. Semantically, they are just syntactic sugar for a normal function definition. Like nested function definitions, lambda forms can reference variables from the containing scope: >>> def make_incrementor(n): [링크 : http://docs.python.org/tutorial/controlflow.html] |
아무튼,
>>> f <function <lambda> at 0xb754da3c> |
위의 예제 실행후 f만 입력하면 위와 같이 fuction <lambda> 라는 말이 나온다.
일종의 간단한 return이 필요없는 함수 - c에서 inline 함수? - 가 되는 것처럼 보인다.
'Programming > python(파이썬)' 카테고리의 다른 글
파이썬의 데이터 타입(딕셔너리,리스트,문자열) - python data types dictionary/list/string (0) | 2010.01.22 |
---|---|
파이썬 종료하기 - how to exit python shell (0) | 2010.01.22 |
파이썬 문자열 선언 - Python String (6) | 2010.01.21 |
파이썬 클래스 - python class decalaration (0) | 2010.01.21 |
파이썬 변수 선언 - python variable declaration (0) | 2010.01.21 |