Certified Associate in Python Programming (PCAP-31-03) — Question 86

What is the expected output of the following code?

myli = [1, 2, 4]
m = list(map(lambda x: 2**x, myli))
print(m[-1])

Answer options

Correct answer: D

Explanation

The code raises each element of 2 to the power of the numbers in the list 'myli', which results in the list [2^1, 2^2, 2^4] or [2, 4, 16]. The last element, m[-1], corresponds to 16, making option D the correct choice. Options A and B are incorrect as they do not match the output, and C is wrong since no exceptions are raised.