[λ¨Έμ λ¬λ] νμ΄μ¬ λλ€(lambda) ν¨μ
[νμ΅ μλ£] [λ¨Έμ λ¬λ κ°μ 04] νμ΄μ¬(Python) ν¨μ λλ€

Anonymous FunctionsλΌκ³ λΆλ¦¬μ°λ 'λλ€ ν¨μ'λ
ν¨μλ₯Ό ν μ€μ μμ±νλ λ°©λ²μ΄λ©°, μμΉ λ―ΈλΆκ³Ό νμ±ν ν¨μμ μ¬μ©λλ€.
π€μ¬μ©λ°©λ²π€
ν¨μλͺ = lambda μ λ ₯1, μ λ ₯2, ... : λ체λλ ννμ
#lambda ν¨μ
f = lambda x : x+100
for i in range(3):
print(f(i))β
OUTPUT >>
100
101
102
#lambda ν¨μ
def print_hello():
print("hello python")
def test_lambda(s, t):
print("input1 ==", s ,", input2 ==", t)
#main
s = 100
t = 200
fx = lambda x, y : test_lambda(s, t)
fy = lambda x, y : print_hello()
#νΈμΆ
fx(500, 1000)
fy(300, 600)
μ΄μ κ°μ μ½λλ₯Ό 보μ. fxλ test_lambda ν¨μλ‘ λ체λκ³ , fyλ print_hello ν¨μλ‘ λ체λλ€.
κ·Έλ¬λ―λ‘ fxμμ μ£Όμ΄μ§ 500, 1000μ κ²°κ³Όμ μΌλ‘ μ¬μ©λμ§ μμ κ²μ΄λ€. test_lambda ν¨μλ‘ λ체λκΈ° λλ¬Έμ΄λ€. μ¦, λ©μΈμμ μ£Όμ΄μ§ sμ tμ κ°μ΄ test_lambdaμμ μ£Όμ΄μ§ ννλ‘ μΆλ ₯λ κ²μ΄λ€.
fy λν, μ무리 μΈμ κ°μ΄ μ£Όμ΄μ§λ€κ³ νλλΌλ print_hello ν¨μλ‘ λ체λλ©΄, κ²°κ³Όμ μΌλ‘λ μΈμμ κ΄κ³μμ΄ "hello python"μ΄ μΆλ ₯λ κ²μ΄λ€.
OUTPUT>>
input1 == 100 , input2 == 200
hello python
πΎλ¨Έμ λ¬λ04κ° μπΎ