람다 표현식은 함수의 기능을 런타임에 생성해서 사용할 수 있는 익명 함수이다.
보통 함수 def라는 키워드를 통해 기능을 정의하고 여러 코드에서 해당 함수를 호출하여
사용 할 수 있지만 람다 표현식은 한번 쓰고 버리는 일시적인 함수이다. 람다 표현식은
함수를 간편하게 작성할 수 있어서 다른 함수의 인수로 넣을 때 주로 사용한다.
다음 코드를 실행해보고 출력결과를 확인한다.
import types f = lambda x,y,z : x+y+z print(f) #<function <lambda> at 0x000002215353AF70> print(type(f)) #<class 'function'> print( type(f) == types.LambdaType) #True
types.FunctionType
types.LambdaType - The type of user-defined functions and functions created by lambda expressions.
types.GeneratorType - The type of generator-iterator objects, produced by calling a generator function.
types.CodeType - The type for code objects such as returned by compile().
types.MethodType - The type of methods of user-defined class instances.
types.BuiltinFunctionType
types.BuiltinMethodType - The type of built-in functions like len() or sys.exit(), and methods of built-in classes. (Here, the term “built-in” means “written in C”.)
types.ModuleType - The type of modules.
types.TracebackType - The type of traceback objects such as found in sys.exc_info()[2].
types.FrameType - The type of frame objects such as found in tb.tb_frame if tb is a traceback object.
types.GetSetDescriptorType - The type of objects defined in extension modules with PyGetSetDef, such as FrameType.f_locals or array.array.typecode. This type is used as descriptor for object attributes; it has the same purpose as the property type, but for classes defined in extension modules.
types.MemberDescriptorType - The type of objects defined in
extension modules with PyMemberDef, such as datetime.timedelta.
days. This type is used as descriptor for simple C data members
which use standard conversion functions; it has the same purpose
as the property type, but for classes defined in extension modules.