Lambda Functions in Python
Veeg om het menu te tonen
All the functions you've created so far are stored in memory after running the code for the first time. However, sometimes you may not want to define a separate function especially for simple, straightforward tasks. In these cases, lambda function can be useful, as it creates anonymous functions.
lambda var1, var2, ... : expression
But not all functions discussed can be converted into lambda functions. Typically, lambda functions are best suited for concise operations that fit within a single line.
12345# Define lambda function sum_squared = lambda x, y: (x + y) ** 2 # Test print('Sum of 2 and 3 squared is', sum_squared(2, 3))
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 6. Hoofdstuk 11
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Sectie 6. Hoofdstuk 11