PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Easy

Question 13

Q483 - Functions


What is the expected output of the following code?



  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: C

Explanation

Topics: lambda list map() string.upper() list indexing


Try it yourself:


Explanation:

The map() function executes a specified function for each item in an iterable.

The item is sent to the function as a parameter.

map(function, iterables)

https://www.w3schools.com/python/ref_func_map.asp


The lambda function will return for each passed string

the first character of it as a capital letter.

And at index 1 will be B

Q483 (Please refer to this number, if you want to write me about this question.)

A. The lambda function in the map operation returns the first character of each element in uppercase. Therefore, the output will be a list of the first characters of each element in uppercase, which is ['A', 'B', 'C']. Accessing the element at index 1 will return 'B', not 'A'.

B. The lambda function in the map operation returns the first character of each element in uppercase. Therefore, the output will be a list of the first characters of each element in uppercase, which is ['A', 'B', 'C']. Accessing the element at index 1 will return 'B', not 'C'.

C. The lambda function in the map operation takes each element of the list 'vect' and returns the first character of each element in uppercase. Therefore, the output will be a list of the first characters of each element in uppercase, which is ['A', 'B', 'C']. Accessing the element at index 1 (zero-based indexing) will return 'B'.

D. The lambda function in the map operation returns the first character of each element in uppercase. Therefore, the output will be a list of the first characters of each element in uppercase, which is ['A', 'B', 'C']. Joining these characters together will result in 'ABC', not the expected output of 'B'.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need