ラムダ関数

Pythonの関数入門

Hugo Bowne-Anderson

Instructor

ラムダ関数

raise_to_power = lambda x, y: x ** y

raise_to_power(2, 3)
8
Pythonの関数入門

無名関数

  • 関数 map は2引数: map(func, seq)

  • map() は関数をシーケンス内の全要素に適用

nums = [48, 6, 9, 21, 1]

square_all = map(lambda num: num ** 2, nums)

print(square_all)
<map object at 0x103e065c0>
print(list(square_all))
[2304, 36, 81, 441, 1]
Pythonの関数入門

練習しましょう!

Pythonの関数入門

Preparing Video For Download...