Python-Quizzes | Python List Quiz | Question 18
Question 18: Find the output of the following program:
temp = ['Geeks', 'for', 'Geeks'] arr = [i[0].upper() for i in temp] print(arr) |
(A) [‘G’, ‘F’, ‘G’]
(B) [‘GEEKS’, ‘FOR’, ‘GEEKS’]
(C) [‘GEEKS’]
(D) Compilation error
Answer: (A)
Explanation: The variable i is used to iterate over each element in list temp. i[0] represent the character at 0th index of i and .upper() function is used to capitalize the character present at i[0].
Quiz of this Question



