lambda functions
All the functions we defined were previously saved in memory after the first code running. But sometimes there is no need to define a separate function, especially if we need to make simple actions. In that case, we can define anonymous Lambda functions in Python have the following syntax:
lambda var1, var2, ... : something...
For example, we can rewrite our first function with lambda function (returns the sum of two numbers squared)
1234# define lambda function sq = lambda x, y: (x+y)**2 # test it print('Sum of 2 and 3 squared is', sq(2,3))
Swipe to start coding
Define a lambda function doing the same as in Chapter 2 (function with three arguments which returns the sum of tripled first number, doubled second and third and all raised to the second power.)
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 2.33Awesome!
Completion rate improved to 2.33
lambda functions
All the functions we defined were previously saved in memory after the first code running. But sometimes there is no need to define a separate function, especially if we need to make simple actions. In that case, we can define anonymous Lambda functions in Python have the following syntax:
lambda var1, var2, ... : something...
For example, we can rewrite our first function with lambda function (returns the sum of two numbers squared)
1234# define lambda function sq = lambda x, y: (x+y)**2 # test it print('Sum of 2 and 3 squared is', sq(2,3))
Swipe to start coding
Define a lambda function doing the same as in Chapter 2 (function with three arguments which returns the sum of tripled first number, doubled second and third and all raised to the second power.)
Oplossing
Bedankt voor je feedback!
single
Awesome!
Completion rate improved to 2.33
lambda functions
Veeg om het menu te tonen
All the functions we defined were previously saved in memory after the first code running. But sometimes there is no need to define a separate function, especially if we need to make simple actions. In that case, we can define anonymous Lambda functions in Python have the following syntax:
lambda var1, var2, ... : something...
For example, we can rewrite our first function with lambda function (returns the sum of two numbers squared)
1234# define lambda function sq = lambda x, y: (x+y)**2 # test it print('Sum of 2 and 3 squared is', sq(2,3))
Swipe to start coding
Define a lambda function doing the same as in Chapter 2 (function with three arguments which returns the sum of tripled first number, doubled second and third and all raised to the second power.)
Oplossing
Bedankt voor je feedback!