익명 함수

(람다 함수에서 넘어옴)

1 개요[ | ]

anonymous function, function constant, function literal, lambda function
익명 함수, 람다 함수, 축약 함수
  • 대리자나 식 트리 형식을 만드는 데 사용할 수 있음

2 Python 예시[ | ]

print( (lambda x: x*x)(5) )
# 25
print( lambda x: x*x )
# <function <lambda> at 0x02D30390>
def square(x): return x*x
print( square )
# <function square at 0x02D678A0>
filter, map, reduce (Python 3)
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 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}