Lists Class 11
Lists Class 11
CHAPTER 01
Lists in Python
In this Chapter...
l Creating a List l Membership Operators
Chapter
Practice
Ans. (c) insert () function is used to insert an element at specified
PART 1 position in the list. This method takes two arguments : one
for index number and second for element value.
Objective Questions Syntax list_name.insert(index, element)
6. Choose the correct option for the following.
l
Multiple Choice Questions l1 = [2, 5, 7]
1. Which value is used to represent the first index of l = l1 + 5
list? print (l)
(a) [7, 10, 12]
(a) 1 (b) 0
(b) [2, 5, 7, 5]
(c) −1 (d) a
(c) [5, 2, 5, 7]
Ans. (b) To access the list’s elements, index number is used. The
index number should be an integer. Index of 0 refers to first (d) TypeError
element, 1 refers to second element and so on. Ans. (d) + operator cannot add list with other type as number or
string because this operator is used only with list types.
2. Choose the output of following Python code. So, it will give TypeError as it can only concatenate list (not
1 = list () “int”) to list.
print ( 1)
(a) [] (b) ()
7. What is the output of following code?
l1 = [3, 2, 6]
(c) [,] (d) Empty
l = l1 * 2
Ans. (a) Empty list can be created in Python using []. To create
empty list, list () is also used.
print (l)
(a) [3, 2, 6, 3, 2, 6]
3. Suppose list (b) [6, 4, 12]
1 = [10, 20, 30, 40, 50, 60, 70] (c) [3, 4, 12]
print( 1[ −3]) (d) TypeError
(a) 30 (b) 50 Ans. (a) * operator can repeat the elements of the list.
(c) 40 (d) Error Syntax list = list1 * digit
Ans. (b) The index of −1 refers to the last element, −2 refers to the
8. Which of the following is true regarding lists in
second last element and so on. Hence, −3 refers to third last
element, i.e. 50.
Python?
(a) Lists are immutable.
4. Choose the output from following code. (b) Size of the lists must be specified before its initialisation.
list1 = [‘A’, ‘R’, ‘I’,‘H’,‘A’,‘N’,‘T’] (c) Elements of lists are stored in contiguous memory
print (list1 [7]) location.
(d) size(list1) command is used to find the size of lists.
(a) T (b) N
(c) A (d) Error Ans. (c) Elements of lists are stored in contiguous memory
location, so it is true regarding lists in Python.
Ans. (d) In the given code, we are trying to access 8th element
from the list which does not exist as we are having total 7 9. Suppose list1 is [56, 89, 75, 65, 99], what is the
elements for which the last index is 6. So, Python will give output of list1 [− 2]?
an IndexError. (a) Error (b) 75
5. Which function is used to insert an element at (c) 99 (d) 65
specified position in the list? Ans. (d) −1 corresponds to the last index in the list, −2 represents
(a) extend () (b) append () the second last element and so on.
So, the output for list1 [− 2] is 65 because 65 is second last
(c) insert () (d) add ()
element of list1.
10. Identify the output of following code. 16. Which method will empty the entire list?
List1=[1, 2, 3, 7, 9] (a) pop() (b) clear()
(c) sort() (d) remove()
L=List1.pop(9)
Ans. (b) clear() method is used to remove all the items of a list.
print(L)
This method will empty the entire list.
(a) Syntax error (b) 9
Syntax
(c) [1, 2, 3, 7] (d) None of these
list_name.clear()
Ans. (a) In pop(9), parentheses put index number instead of
element. In the given list, maximum index number is 4, then 17. Which of the following allows us to sort the list
9 is out of index range. elements in descending order?
11. Suppose list1 is [2445,133,12454,123], what is the (a) reverse = True
output of max(list1)? (b) reverse = False
(a) 2445 (b) 133 (c) sort (descending)
(c) 12454 (d)123 (d) sort. descending
Ans. (c) max() returns the maximum element in the list. From Ans. (a) sort() is used to sort the given list in ascending order. The
given options, 12454 is the element with maximum value. sort() has an argument called reverse = True. This allows us
to sort the list elements in descending order.
12. To add a new element to a list, which command will
we use? 18. Identify the correct output.
(a) list1.add(8) >>>l1 = [34, 65, 23, 98]
(b) list1.append(8) >>>l1. insert(2, 55)
(c) list1.addLast(8) >>> l1
(a) [34, 65, 23, 55] (b) [34, 55, 65, 23, 98]
(d) list1.addEnd(8)
(c) [34, 65, 55, 98] (d) [34, 65, 55, 23, 98]
Ans. (b) We use the function append() to add an element to the
Ans. (d) insert() is used to insert an element at specified position
list.
in the list. This method takes two arguments : one for index
13. What will be the output of the following Python number and second for element value.
code? Syntax
list1=[9, 5, 3, 5, 4] list_name.insert(index, element)
list1[1:2]=[7,8] 19. Find the output from the following code.
print(list1) list1=[2, 5, 4, 7, 7, 7, 8, 90]
(a) [9,5, 3, 7, 8] (b) [9, 7, 8, 3, 5, 4] del list1[2 : 4]
(c) [9,[ 7, 8], 3, 5,4] (d) Error print(list1)
Ans. (b) In the piece of code, slice assignment has been (a) [2, 5, 7, 7, 8, 90] (b) [5, 7, 7, 7, 8, 90]
implemented. The sliced list is replaced by the assigned (c) [2, 5, 4, 8, 90] (d) Error
elements in the list. Ans. (a) del keyword is used to delete the elements from the list.
14. Consider the declaration a=[2, 3, ‘Hello’, 23.0]. 20. Slice operation is performed on lists with the use of
Which of the following represents the data type of (a) semicolon (b) comma
‘a’? (c) colon (d) hash
(a) String (b) Tuple Ans. (c) In Python list, there are multiple ways to print the whole
(c) Dictionary (d) List list with all the elements, but to print a specific range of
Ans. (d) List contains a sequence of heterogeneous elements elements from the list, we use slice operation. Slice
which store integer, string as well as object. It can created to operation is performed on lists with the use of colon (:).
put elements separated by comma (,) in square brackets [].
15. Identify the output of the following Python
l
Case Based MCQs
statement. 21. Suppose that list L1
x = [[1, 2, 3, 4], [5, 6, 7, 8]] [“Hello”, [“am”, “an”], [“that”, “the”, “this”], “you”,
y = x [0] [2] “we”, “those”, “these”]
print(y) Based on the above information, answer the
(a) 3 (b) 4 following questions.
(c) 6 (d) 7
(i) Find the output of len (L1).
Ans. (a) x is a list, which has two sub-lists in it. Elements of first
(a) 10 (b) 7
list will be represented by [0] [i] and elements of second list
will be represented by [1] [i]. (c) 6 (d) Error
(ii) Find the output of L1[3 : 5]. 2. list1 = [45, 77, 87, ‘Next’, ‘Try’, 33, 43]
(a) [“that”, “the”, “this”] (b) [“we”, “those”] Observe the given list and find the answer of
(c) [“you”, “we”] (d) [you, we] questions that follows.
(iii) What will be the output of L1[5:] +L1[2]? (i) list1[−2] (ii) list1[2]
(a) [‘those’, ‘these’, ‘that’, ‘the’, ‘this’] Ans. (i) 33 (ii) 87
(b) [‘those’, ‘these’]
3. Distinguish between string and list.
(c) [‘that’, ‘the’, ‘this’]
Ans. Strings are immutable, which means the values provided to
(d) Error
them will not change in the program. While lists are
(iv) Choose the correct output of mutable which means the values of list can be changed at
print (L1[6:]) any point of time in program.
(a)“those” (b) “these” 4. What is the output of below questions?
(c) “those”, “these” (d) None of these l2 = [75, 43, 40, 36, 28, 82]
(v) Give the correct statement for (i) l2.sort ( )
[‘Hello’, [‘am’, ‘an’], [‘that’, ‘the’, ‘this’], ‘you’, ‘we’, (ii) l2.sort (reverse = True)
‘those’, ‘these’] Ans. (i) [28, 36, 40, 43, 75, 82]
(a) L1[] (b) L1[:] (ii) [82, 75, 43, 40, 36, 28]
Answers
Multiple Choice Questions
1. (b) 2. (d) 3. (b) 4. (b) 5. (c) 6. (c)