Python-Quizzes | Python List Quiz | Question 18

Question 18: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

temp = ['Geeks', 'for', 'Geeks'
arr = [i[0].upper() for i in temp] 
print(arr) 

chevron_right


(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

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.