Home › Free notes › Class 11 Computer Science › Lists
Lists – Class 11 Computer Science notes, important questions and MCQs
NCERT Class 11 Computer Science, chapter 9. Notes, key terms, important questions with answers and MCQs.
Chapter overview
A list is an ordered, mutable sequence of elements enclosed in square brackets, and its elements can be of different data types. Lists support indexing, slicing, concatenation, repetition and membership, and they can be changed in place. Python provides many list methods and built-in functions, and lists can be nested, copied and passed to functions.
List operations
- Creating: L = [10, 20, 30, 40]; indexing L[0] is 10 and L[-1] is 40; slicing L[1:3] is [20, 30].
- Lists are mutable: L[1] = 25 changes the second element; concatenation [1, 2] + [3] gives [1, 2, 3]; repetition [0] * 3 gives [0, 0, 0]; membership 20 in L tests presence.
- Traversal uses for x in L or for i in range(len(L)); nested lists such as M = [[1, 2], [3, 4]] are accessed as M[1][0], which is 3.
Methods, copying and functions
- Methods: append(x) adds one element at the end; extend(list) adds many; insert(i, x) inserts at position i; remove(x) deletes the first occurrence; pop(i) removes and returns the element at i (last by default); count(), index(), reverse(), sort(); built-ins len(), sorted(), min(), max(), sum() and list().
- Assignment L2 = L1 makes both names refer to the same list, so changes appear in both; a true copy is made with L1.copy(), list(L1) or L1[:].
- When a list is passed to a function, changes made to it inside the function are reflected outside because lists are mutable; sort() changes the list in place and returns None, while sorted() returns a new list.
Key terms
- List
- an ordered, mutable sequence in square brackets
- append()
- a method that adds one element at the end of a list
- extend()
- a method that adds all elements of another sequence
- Nested list
- a list that contains other lists as elements
- Aliasing
- two names referring to the same list object
Important questions with answers
Distinguish between append() and extend().2 marks
append(x) adds its argument as a single element at the end of the list, so L.append([4, 5]) adds a nested list. extend(seq) adds each element of the sequence separately, so L.extend([4, 5]) adds 4 and 5 as two elements.
Distinguish between sort() and sorted().3 marks
sort() is a list method that sorts the list in place and returns None; it works only on lists. sorted() is a built-in function that returns a new sorted list without changing the original and can be used with any iterable, such as a tuple or string.
Write a program to find the largest, smallest and average of numbers in a list without using max(), min() or sum(), and explain it.5 marks
The program uses traversal to compute the results. L = [45, 12, 78, 34, 9]; largest = smallest = L[0]; total = 0; for x in L: if x > largest: largest = x; if x < smallest: smallest = x; total = total + x. Then average = total / len(L), and print('Largest:', largest, 'Smallest:', smallest, 'Average:', average). Explanation: largest and smallest are initialised with the first element, so they always hold a value from the list. The for loop visits each element. If the current element is greater than largest, largest is updated; if it is smaller than smallest, smallest is updated. Each element is also added to total. After the loop, the average is calculated by dividing total by the number of elements obtained with len(). For the given list, the output is Largest: 78, Smallest: 9 and Average: 35.6. This approach, called linear traversal, checks every element once and is the basis of many list algorithms such as linear search and counting. Using the built-in functions max(L), min(L) and sum(L) would give the same results more briefly.
Quick revision
- Creating, indexing and slicing lists.
- Mutability; concatenation, repetition, membership.
- List methods and built-in functions.
- Copying lists; lists as function arguments.
Exam tips
- append() adds one element; extend() adds each element of a sequence.
- Use L.copy() to avoid aliasing.
Practice MCQs
Lists in Python are enclosed in
- parentheses ()
- braces {}
- square brackets []
- quotes
Show answer
Answer: (c) square brackets []. Example: [1, 2, 3].
The method that adds one element at the end of a list is
- insert()
- add()
- extend()
- append()
Show answer
Answer: (d) append(). L.append(5).
Lists in Python are
- mutable
- immutable
- fixed in size
- only numeric
Show answer
Answer: (a) mutable. Elements can be changed.
If L = [1, 2, 3] and L.extend([4, 5]) is run, L becomes
- [1, 2, 3, [4, 5]]
- [4, 5, 1, 2, 3]
- [1, 2, 3, 4, 5]
- [1, 2, 3, 9]
Show answer
Answer: (c) [1, 2, 3, 4, 5]. extend adds each element.
If L = [10, 20, 30, 40], L.pop() returns
- 10
- 30
- 40
- None
Show answer
Answer: (c) 40. Without an index, pop removes the last element.
For M = [[1, 2], [3, 4]], M[1][0] is
- 2
- 1
- 4
- 3
Show answer
Answer: (d) 3. Row 1, column 0.
After A = [1, 2]; B = A; B.append(3), the value of A is
- [1, 2, 3]
- [1, 2]
- [3]
- an error
Show answer
Answer: (a) [1, 2, 3]. A and B refer to the same list.
The statement x = L.sort() assigns to x
- the sorted list
- None
- the original list
- the length of the list
Show answer
Answer: (b) None. sort() works in place and returns None.
All chapters of Class 11 Computer Science
Written by Kundali IQ from standard, well-established facts to help with revision. This is not an official NCERT publication; always read your textbook too.