Which of the following are true of Python lists Mcq?
Python List MCQsThis section focuses on the "list" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations. Show 1.Which of the following would give an error? A. list1=[] View Answer Ans : D Explanation: None of the above will result in error. 2.Which of the following is True regarding lists in Python? A. Lists are immutable. View Answer Ans : C Explanation: Elements of lists are stored in contagious memory location is True regarding lists in Python. 3.What will be the output of below Python code? print(list1[::-1]) A. [5,9,0,8] View Answer Ans : A Explanation: [5,9,0,8] will be the output of below Python code. 4.Which of the following will give output as [23,2,9,75] ? A. print(list1[1:7:2]) View Answer Ans : C Explanation: print(list1[1:8:2]) of the following will give output as [23,2,9,75]. 5.The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95]. How can the student's average mark be calculated? A. print(avg(list1)) View Answer Ans : B Explanation: the student's average mark be calculated through print(sum(list1)/len(list1)). 6.What will be the output of following Python code? print(min(list1)) A. c View Answer Ans : C Explanation: C will be the output of following Python code. 7.The elements of a list are arranged in descending order. Which of the following two will give same outputs? A. i, ii View Answer Ans : B Explanation: print(list_name.sort()) and print(list_name.reverse()) will give same outputs. 8. What will be the result after the execution of above Python code? list1.pop(3) print(list1) A. [3,2,5,3,6] View Answer Ans : A Explanation: [3,2,5,3,6] will be the result after the execution of above Python code. 9.What will be the output of below Python code? list1.remove(2) print(sum(list1)) A. 18 View Answer Ans : C Explanation: 21 will be the result after the execution of above Python code. 10.What will be the output of below Python code? list1.insert(5,8) print(list1) A. ["tom", "mary", "simon", 5] View Answer Ans : B Explanation: ["tom", "mary", "simon", 8] will be the result after the execution of above Python code. Discussion * You must be logged in to add comment. vanur swamy it is very easy to understand Q1. Which of the following statement will create list?a. L1=list( ) b. L1=[1,2,3,4] c. Both of the above d. None of the above Ans. c. Both of the above 9.16. Multiple Choice Questions¶
Q-1: What is returned by the following function? def slice_exercise(): alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False] print(alist[2:4])
Q-2: What is returned by the following function? def len_of_list(): alist = [3, 67, "cat", 3.14, False] return len(alist)
Q-3: What is returned by the following function? def indexing_and_upper(): alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False] return alist[2].upper()
Q-4: What is returned by the following function? def list_within_list(): alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False] return alist[2][0]
Q-5: What is returned by the following function? def list_transformation(): alist = [4, 2, 8, 6, 5] blist = [alist] * 2 alist[3] = 999 return blist
Q-6: What is returned by the following function? def list_transformation(): alist = [4, 2, 8, 6, 5] blist = [ ] for item in alist: blist.append(item+5) return blist
Q-7: Which method would you use to figure out the position of an item in a list?
Q-8: Which method is best to use when adding an item to the end of a list?
Q-9: Given that we want to accumulate the total sum of a list of numbers, which of the following accumulator patterns would be appropriate? def find_sum(): nums = [4, 5, 2, 93, 3, 5] s = 0 for n in nums: s = s + 1 return s def find_sum(): nums = [4, 5, 2, 93, 3, 5] s = 0 for n in nums: s = n + n return s def find_sum(): nums = [4, 5, 2, 93, 3, 5] s = 0 for n in nums: s = s + n return s
Q-10: Given that we want to accumulate the total number of strings in the list, which of the following accumulator patterns would be appropriate? def num_of_strings(): lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]] s = 0 for n in lst: s = s + n return s def num_of_strings(): lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]] for item in lst: s = 0 if isinstance(item, str): s = s + 1 return s def num_of_strings(): lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]] s = "" for n in lst: s = s + n return s def num_of_strings(): lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]] s = 0 for item in lst: if isinstance(item, str): s = s + 1
Q-11: What will the following code print? def mystery(num_list): index = 0 while index < len(num_list): num = num_list[index] if num == 0: num_list.pop(index) index += 1 list1 = [3, 0, 2, 0, 0] mystery(list1) print(list1)
Q-12: What will the following code print? def mystery(num_list): sum = 0 for i in range(0, len(num_list), 2): num = num_list[i] sum += num return sum list1 = [1, 2, 3, 4, 5] print(mystery(list1))
Q-13: What will the following code print? def mystery(num_list): for num in num_list: if num < 0: return False else: return True print(mystery([3, -1, 2]))
Q-14: What will the following code print? def mystery(num_list): out = [] for num in num_list: if num > 10: out.append(num) return out print(mystery([5, 10, 15, 20]))
Q-15: What will the following code print? def mystery(num_list): out = [] for i in range(len(num_list) - 1,0,-1): num = num_list[i] out.append(num) return out print(mystery([5, 10, 15, 20])) Python Lists and Tuples QuizInteractive Quiz ⋅ 11 Questions Test your understanding of Python lists and tuples. Take this quiz after reading our Lists and Tuples in Python tutorial. The quiz contains 11 questions and there is no time limit. You’ll get 1 point for each correct answer. At the end of the quiz, you’ll receive a total score. The maximum score is 100%. Good luck! Start the Quiz » « Browse All Python Quizzes |