VOOZH about

URL: https://www.geeksforgeeks.org/python/output-python-program-set-11lists/

⇱ Output of python program | Set 11(Lists) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Output of python program | Set 11(Lists)

Last Updated : 23 Jul, 2025

Pre-requisite: List in python 1) What is the output of the following program? 

a) [[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]] b) [[2, 3, 9], [2, 3, 9], [2, 3, 9]] c) [[[2, 3, 9]], [[2, 3, 9]]] d) None of these Ans. (a) Explanation: [x for x in[data] returns a new list copying the values in the list data and the outer for statement prints the newly created list 3 times. 2) What is the output of the following program? 

a) [0, 2, 4, 6] b) [0, 2, 4] c) [0, 1, 2, 3, 4, 5] d) Runtime error Ans. (b) Explanation: The is statement checks whether the value lies in list data and if it does whether it's divisible by 2. It does so for x in (0, 7). 3) What is the output of the following program? 

a) ['G', 'F', 'G'] b) ['GEEKS'] c) ['GEEKS', 'FOR', 'GEEKS'] d) Compilation error Ans. (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]. 4) What is the output of the following program? 

a) [2, 2, 6, 4, 4] b) Compilation error c) Runtime error d) ['2', '2', '5', '3', '6', '4', '4', '5'] Ans. (a) Explanation: This is an example of nested list comprehension. The inner list created contains a list of integer in temp. The outer list only procures those x which are a multiple of 2. 5) What is the output of the following program? 

a) [2, 2, 9, 6, 6] b) [] c) Compilation error d) Runtime error Ans. (b) Explanation: Since here x have not been converted to int, the condition in the if statement fails and therefore, the list remains empty.

Comment
Article Tags: