Knowee
Questions
Features
Study Tools

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))

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))

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given Python code will be:

9 27 81

Explanation:

The given Python code defines a list of lambda functions, each of which takes an argument x and raises it to the power of 2, 3, and 4 respectively.

Then it iterates over this list of functions, and for each function, it calls the function with the argument 3.

So, for the first function, it calculates 32 which is 9. For the second function, it calculates 33 which is 27. And for the third function, it calculates 3**4 which is 81.

Hence, the output of the code is 9, 27, and 81, each on a new line.

This problem has been solved

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

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)

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)

What does the following lambda function return? f = lambda x: x*2 print(f(3)) Answer( Please choose a correct answer )   CLEAR2369

. What will be the output of the following code snippet?x = [i for i in range(6)]y = [i**3 for i in x]print(y) [0, 1, 8, 27, 64, 125][1, 8, 27, 64, 125, 216][0, 1, 4, 9, 16, 25][0, 1, 8, 27, 64]

1/3

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.