Lambda-functies

Introductie tot functies in Python

Hugo Bowne-Anderson

Instructor

Lambda-functies

raise_to_power = lambda x, y: x ** y

raise_to_power(2, 3)
8
Introductie tot functies in Python

Anonieme functies

  • De functie map neemt twee argumenten: map(func, seq)

  • map() past de functie toe op ALLE elementen van de sequentie

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]
Introductie tot functies in Python

Laten we oefenen!

Introductie tot functies in Python

Preparing Video For Download...