For Exercise 4, you are given the following questions and answers.
Q: f
A: f = 3
This is essentially variable assignment.
Q: f()
A: f = lambda: 3
This is similar to a function that takes in no arguments and returns the value 3.
Q: f(3)
A: f = lambda x: x
This is similar to a function that takes in the argument x
and returns the value x
. So you are given the value 3
and a value of 3
is returned.
Q: f()()
A: f = lambda: lambda: 3
This is similar to a function that takes in no arguments and returns another function that again takes no arguments which will return the value 3
.
Q: f()(3)()
A: f = lambda: lambda x: lambda: x
Like the previous example, this will return 3
. You have function that takes in no arguments but returns another function that takes in the value x
and returns another function that takes in no arguments but returns the value x
.
By following the examples above, you can solve Exercise 5 in a similar fashion.
Additionally, Exercise 5 has been explained pretty well in the comments by ChrisP.