lambda 인자 : 표현식
>>> def hap(x, y):
... return x + y
...
>>> hap(10, 20)
30
>>> (lambda x,y: x + y)(10, 20)
30
>>> list(map(lambda x: x ** 2, range(5))) # 파이썬 2 및 파이썬 3
[0, 1, 4, 9, 16]
>>> from functools import reduce # 파이썬 3에서는 써주셔야 해요
>>> reduce(lambda x, y: x + y, [0, 1, 2, 3, 4])
10
>>> list(filter(lambda x: x < 5, range(10))) # 파이썬 2 및 파이썬 3
[0, 1, 2, 3, 4]
import types
f = lambda x,y,z : x+y+z
print(f)
print(type(f))
print( type(f) == types.LambdaType)
<function <lambda> at 0x033E90B8>
<class 'function'>
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.