Question: Q 3 : WWPD: Lambda Use Ok to test your knowledge with the following What Would Python Display? questions: python 3 ok - q lambda

Q3: WWPD: Lambda
Use Ok to test your knowledge with the following "What Would Python Display?" questions:
python3 ok -q lambda -u
As a reminder, the following two lines of code will not display any output in the interactive Python interpreter when executed:
>>> x = None
>>> x
>>>
>>> lambda x: x # A lambda expression with one parameter x
______
>>> a = lambda x: x # Assigning the lambda function to the name a
>>> a(5)
______
>>>(lambda: 3)() # Using a lambda expression as an operator in a call exp.
______
>>> b = lambda x, y: lambda: x + y # Lambdas can return other lambdas!
>>> c = b(8,4)
>>> c
______
>>> c()
______
>>> d = lambda f: f(4) # They can have functions as arguments as well.
>>> def square(x):
... return x * x
>>> d(square)
______
>>> higher_order_lambda = lambda f: lambda x: f(x)
>>> g = lambda x: x * x
>>> higher_order_lambda(2)(g) # Which argument belongs to which function call?
______
>>> higher_order_lambda(g)(2)
______
>>> call_thrice = lambda f: lambda x: f(f(f(x)))
>>> call_thrice(lambda y: y +1)(0)
______
>>> print_lambda = lambda z: print(z) # When is the return expression of a lambda expression executed?
>>> print_lambda
______
>>> one_thousand = print_lambda(1000)
______
>>> one_thousand # What did the call to print_lambda return?
______

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!