What will be the output of the following Python code?L = [lambda x: x ** 2, lambda x: x ** 3, lambda x: x ** 4] for f in L: print(f(3)) 2781343 6912 92781 None of the mentioned
Question
What will be the output of the following Python code?L = [lambda x: x ** 2, lambda x: x ** 3, lambda x: x ** 4] for f in L: print(f(3)) 2781343 6912 92781 None of the mentioned
Solution
The output of the given Python code will be:
9 27 81
Here's the step by step explanation:
-
The list
Lcontains three lambda functions. Each function takes an argumentxand raises it to the power of 2, 3, and 4 respectively. -
The
forloop iterates over each function in the listL. -
In each iteration, the function
fis called with the argument3. -
The results of these function calls are printed out.
So, for the first function, 3 is raised to the power of 2, which gives 9. For the second function, 3 is raised to the power of 3, which gives 27. And for the third function, 3 is raised to the power of 4, which gives 81.
Similar Questions
What will be the output of the following Python code? lamb = lambda x: x ** 3 print(lamb(5))0 points15555125None of the above
What does the following lambda function return? f = lambda x: x*2 print(f(3)) Answer( Please choose a correct answer ) CLEAR2369
What is the output of the following code in Python?
What will be the output of the following Python code?l=[[1, 2, 3], [4, 5, 6]]for i in range(len(l)): for j in range(len(l[i])): l[i][j]+=10print(l)
9. What will be the output of the following Python code?x = (i for i in range(3))for i in x: print(i)for i in x: print(i)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.