5 MCQ Class 11th LIST
5 MCQ Class 11th LIST
: 9810301034
Python Questions and Answers – Lists – 1
1. Which of the following commands will create a list? 6. Suppose list1 is [1, 5, 9], what is sum(list1) ?
a) list1 = list() b) list1 = []. a) 1 b) 9 c) 15 d) Error
c) list1 = list([1, 2, 3]) d) all of the mentioned 7. To shuffle the list(say list1) what function do we use ?
2. What is the output when we execute list(“hello”)? a) list1.shuffle() b) shuffle(list1)
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]. b) [‘hello’]. c) random.shuffle(list1) d) random.shuffleList(lit1)
c) [‘llo’]. d) [‘olleh’]. 8. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following
3. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is is correct syntax for slicing operation ?
len(listExample)? a) print(list1[0]) b) print(list1[:2])
a) 5 b) 4 c) None d) Error c) print(list1[:-2]) d) all of the mentioned
4. Suppose list1 is [2445,133,12454,123], what is max(list1) ? 9. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
a) 2445 b) 133 c) 12454 d) 123 a) Error b) None c) 25 d) 2
5. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ? 10. Suppose list1 is [2, 33, 222, 14, 25],What is list1[:-1]?
a) 3 b) 5 c) 25 d) 1 a) [2, 33, 222, 14]. b) Error c) 25 d) [25, 14, 222, 33, 2].
SOLUTION
Ans 1. d Execute in the shell to verify Ans 7. c Execute in the shell to verify .
Ans 2. a Execute in the shell to verify. Ans 8. d Slicing is allowed in lists just as in the case of
Ans 3. a Execute in the shell and verify. strings.
Ans 4. c Max returns the maximum element in the list. Ans 9. c -1 corresponds to the last index in the list.
Ans 5. d Min returns the minimum element in the list. Ans 10. a Execute in the shell to verify.
Ans 6. c Sum returns the sum of all elements in the list.
SOLUTION
Ans 1. d Execute in the shell to verify. Ans 5. b Elements are compared one by one.
Ans 2. b When assigning names1 to names2, we create a Ans 6. b We use the function append to add an element to
second reference to the same list. Changes to names2 affect the list.
names1. When assigning the slice of all elements in names1 Ans 7. a Execute in the shell to verify.
to names3, we are creating a full copy of names1 which can Ans 8. d Execute help(list.index) to get details.
be modified independently. Ans 9. 0
Ans 3. c Execute in the shell and verify. Ans 10. d Execute in the shell to verify.
Ans 4. c Execute in the shell to verify.
SOLUTION
Ans 1. d Execute in the shell to verify. Ans 6. a Execute in the shell to verify.
Ans 2. a Execute in the shell to verify. Ans 7. a First time the highest number is encountered is at
Ans 3. c xplanation: pop() removes the element at index 1.
Ans 4. a pop() by default will remove the last element. Ans 8. c Execute in the shell to verify.
Ans 5. a split() function returns the elements in a list. Ans 9. b Lists should be copied by executing [:] operation.
Ans 10. c Execute in the shell to verify.
SOLUTION
Ans 1. b Execute in the shell to verify. Ans 6. d Execute in the shell to verify.
Ans 2. c Execute in the shell to verify. Ans 7. d Execute in the shell to verify.
Ans 3. d Execute in the shell to verify Ans 8. d Execute in the shell to verify.
Ans 4. a Execute in the shell to verify. Ans 9. c Execute in the shell to verify.
Ans 5. d Execute in the shell to verify. Ans 10. c Execute in the shell to verify.
SOLUTION
Ans 1. c The above copy is a type of shallow copy and only changes made in sublist is reflected in the copied list.
Ans 2. d The zip function combines the individual attributes of the lists into a list of tuples.
Ans 3. b The above copy is deepcopy. Any change made in the original list isn’t reflected.
Ans 4. c The partition function only splits for the first parameter along with the separator while split function splits for the
number of times given in the second argument but without the separator.
Page 4 of 6 Computer Science 083 PYTHON [email protected]
MCQ PYTHON LIST By Gajendra Sir Mo. No. : 9810301034
Ans 5. d The above code returns the cumulative sum of elements in a list.
Ans 6. a Variable x iterates over each letter in string a hence the length of each letter is 1.
Ans 7. d The above code returns the cumulative sum of elements in a list.
Ans 8. b The first line of the code creates multiple reference copies of sublist. Hence when 7 is appended, it gets appended
to all the sublists.
Ans 9. c The filter function gives value from the list b for which the condition is true, that is, x%2==1.
Ans 10. a In the piece of code, slice assignment has been implemented. The sliced list is replaced by the assigned elements in
the list. Type in python shell to verify.
SOLUTION
Ans 1. b Append function on lists doesn’t return anything. Ans 2. b List b is just a copy of the original list. Any copy
Thus the value of b is None. made in list b will not be reflected in list a.