1 개요[ | ]
- anonymous function, function constant, function literal, lambda function
- 익명 함수, 람다 함수, 축약 함수
- 대리자나 식 트리 형식을 만드는 데 사용할 수 있음
2 Python 예시[ | ]
Python
Copy
print( (lambda x: x*x)(5) )
# 25
Python
Copy
print( lambda x: x*x )
# <function <lambda> at 0x02D30390>
Python
Copy
def square(x): return x*x
print( square )
# <function square at 0x02D678A0>
- filter, map, reduce (Python 3)
Python
Copy
numbers = [1, 2, 3, 4, 5, 6]
print( list(filter(lambda x: x % 2 == 0, numbers)) )
# [2, 4, 6]
print( list(map(lambda x: x * 2 - 1, numbers)) )
# [1, 3, 5, 7, 9, 11]
import functools
print( functools.reduce(lambda x, y: x + y, numbers) )
# 21
3 같이 보기[ | ]
4 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.