List Methods and Operations in Python (Class 12 Computer Science)
Updated 16 October 2026 · Fact-checked
A Python list is an ordered, mutable sequence written in square brackets. Methods such as append(), extend(), insert(), remove(), sort() and reverse() change the list in place and return None; pop(), count() and index() return a value. Slicing, + and * build new lists, while M = L only gives the same list a second name.
append() adds the whole list [3, 4] as one item, while extend() adds 3 and 4 as separate items.
Illustration drawn for QuestionBuddy.
Understand List Methods and Operations
A list is an ordered collection of items of any type, written in square brackets: L = [10, 'pen', 4.5, [1, 2]]. Items are numbered from 0 on the left and from -1 on the right, so L[0] is 10 and L[-1] is [1, 2]. Unlike a string or a tuple, a list is mutable: L[1] = 'ink' changes the list itself.
Operations that build a new list. + joins two lists, * repeats a list, and slicing L[start:stop:step] copies items from start up to stop - 1. Missing values default to the whole list, and a negative step walks backwards: L[::-1] is a reversed copy. in checks membership and gives True or False. Joining a list to a tuple with + raises TypeError, because both sides must be lists.
Methods that change the list. append(x) adds x as one item at the end, even if x is a list; extend(seq) adds each item of seq; insert(i, x) places x before position i (an index past the end simply appends); remove(x) deletes the first x and raises ValueError if x is missing; sort() arranges the items in ascending order (sort(reverse=True) for descending); reverse() reverses the order. All of these return None, which is why print(L.sort()) prints None.
Methods and functions that give back a value. pop(i) removes and returns the item at i (the last item if i is omitted); count(x) and index(x) report how often and where x first occurs; len(), min(), max() and sum() work on the whole list; sorted(L) returns a new sorted list and leaves L unchanged; list('abc') converts any sequence into a list.
Aliasing. M = L does not copy. Both names point to the same list, so M.append(5) is seen through L as well, and M += [6] also changes L (it extends in place). A real copy is M = L[:] or M = list(L). The same idea explains functions: a list passed as an argument can be changed inside the function, but giving the parameter a new list (L = [1, 2]) only rebinds the local name.
The 2026-27 sample paper opens with exactly this topic (the output of an insert() call), and list traps appear in output, error-finding and 2-3 mark function questions every year, so practise tracing the list after every statement.
List Methods and Operations: key facts
- Methods that change the list (all return None)
append(x) adds x as one item at the end extend(seq) adds every item of seq at the end insert(i, x) puts x before position i; past the end it appends remove(x) deletes the first x; ValueError if x is absent sort() ascending in place; sort(reverse=True) for descending reverse() reverses the order in place - Never write
L = L.sort(): L becomes None. - Methods and functions that return something
pop(i) removes and returns item i; the last item if i is omitted count(x) how many times x occurs index(x) position of the first x; ValueError if absent sorted(L) a new sorted list; L is unchanged len(L), min(L), max(L), sum(L) size, smallest, largest, total list(seq) a new list from any sequence [].pop()raises IndexError: pop from empty list.- Operators on lists
- L1 + L2: a new joined list
- L * n: a new list repeated n times
- x in L: True if x is an item
- L[i:j:k]: a new list from i up to j - 1 in steps of k
- L[::-1]: a reversed copy
- Slicing never raises IndexError; indexing does.
- Copy or alias?
M = L alias; one list with two names M = L[:]: a separate copy M = list(L) a separate copy M += [x] extends the same list, so an alias sees it - For a function argument, changing items changes the caller's list; assigning a new list does not.
- Tuple for contrast
- t = (1, 2, 3) is immutable: t[0] = 5 raises TypeError; t + [4] raises TypeError; t + (4,) gives (1, 2, 3, 4)
- Tuples have only count() and index() as methods.
How to answer List Methods and Operations questions
For any output or error question on lists, trace the list on paper after every line.
- 1Write the list with index numbers under each item (0, 1, 2 ... and -1, -2 ... if negatives are used).
- 2For each method call, ask two questions: does it change the list, and what does it return?
append,extend,insert,remove,sortandreversereturn None. - 3When a list is appended to another, it goes in as one item; count it as one when finding
len(). - 4For slices, list the indexes the slice visits (start, start + step, ...) and stop before
stop; for a negative step, move leftwards. - 5Check names: after
M = L, every change through M is a change to L. - 6For error questions, look for the usual culprits: missing colon,
Print, round brackets used for indexing,rangegoing one past the end,removeorindexof a missing value. - 7Write the final output exactly as Python prints it: square brackets, commas followed by a space, quotes around strings inside a list.
List Methods and Operations in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
insert(), remove() and pop() on a playlist
Suppose a music app keeps the songs to be played next in a list: queue = ['Song A', 'Song B', 'Song C']. The user puts 'Song X' right after the current first song, removes 'Song B', and then the app plays (removes) the first song.
Write the statements and show the queue and the song played.
Try it first, then show the solutionSolution
queue = ['Song A', 'Song B', 'Song C'] queue.insert(1, 'Song X') queue.remove('Song B') playing = queue.pop(0) print(playing, queue)- insert(1, ...) puts 'Song X' before position 1: ['Song A', 'Song X', 'Song B', 'Song C'].
- remove deletes 'Song B'; pop(0) removes and returns the first song.
Answer: Song A ['Song X', 'Song C']
Memory hook: insert squeezes in, remove deletes by value, pop takes out by position and hands it to you.
sorted() versus sort() and aliasing
Imagine a teacher's program stores marks in the order students sat: marks = [72, 95, 64, 88]. A helper writes rank = marks and calls rank.sort(reverse=True) to get a merit order.
What happens to marks? How should the helper get the merit order without disturbing the seating order?
Try it first, then show the solutionSolution
- rank = marks makes an alias, so sort() rearranges the one shared list; marks also becomes [95, 88, 72, 64].
- sorted() returns a new list and leaves the original alone:
marks = [72, 95, 64, 88] rank = sorted(marks, reverse=True) print(marks) print(rank)
Answer: With the alias, marks is changed to [95, 88, 72, 64]. With sorted(): marks stays [72, 95, 64, 88] and rank is [95, 88, 72, 64].
Memory hook: sort() rearranges the shelf itself; sorted() takes a photo and rearranges the photo.
Tricks to remember List Methods and Operations
Short memory aids. Say each one aloud once, then use it on a question the same day.
Append swallows, extend spills
append([1, 2]) swallows the list whole (one new item); extend([1, 2]) spills its items in one by one (two new items).
Use it when: len() and output questions after append/extend.
Doers return None
Methods that do something to the list (append, extend, insert, remove, sort, reverse) give back nothing; only pop hands you the item it removed.
Use it when: Questions like
print(L.reverse())orX = L.sort().Equals is a nickname
M = L gives the same list a nickname; [:] makes a twin.
Use it when: Aliasing traps in output questions.
Slice: start in, stop out
The start index is included and the stop index is left out, whichever direction the step goes.
Use it when: Slicing with positive and negative steps.
List Methods and Operations: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: insert() and append() with a list · 1 mark · Very short answerBoard level
Write the output:
L = [10, 20, 30]
L.insert(1, 15)
L.append([5, 6])
print(L, len(L))Try it first, then show the solutionSolution
- insert(1, 15) puts 15 before position 1: [10, 15, 20, 30].
- append adds the list [5, 6] as a single item, so the length becomes 5.
Answer: [10, 15, 20, 30, [5, 6]] 5
Example 2: Aliasing with += and pop() · 2 marks · Short answerHarder board level
Predict the output:
L = [3, 6, 9]
M = L
M += [12]
L.append([15, 18])
print(L)
print(M.pop(), len(L))Try it first, then show the solutionSolution
- M = L is an alias. M += [12] extends that one list: [3, 6, 9, 12].
- append adds [15, 18] as one item: [3, 6, 9, 12, [15, 18]]. (1 mark)
- M.pop() removes and returns the last item, [15, 18]; L (the same list) now has 4 items. (1 mark)
Answer: [3, 6, 9, 12, [15, 18]]
[15, 18] 4
Example 3: Find and correct the errors · 2 marks · Short answerHarder board level
The code below should print the average of the list, but it has syntax and logical errors. Rewrite it correctly and give the output.
nums = [4, 7, 1, 9]
total = 0
for i in range(1, len(nums) + 1)
total += nums(i)
Print(total / len(nums))Try it first, then show the solutionSolution
- range(1, len(nums) + 1) skips index 0 and then goes past the end; use range(len(nums)), and add the missing colon. (1 mark)
- Items are read with square brackets, nums[i], and the function is print in lower case. (1 mark)
nums = [4, 7, 1, 9] total = 0 for i in range(len(nums)): total += nums[i] print(total / len(nums))- Total = 21, and 21 / 4 = 5.25.
Answer: Corrected code as above; output 5.25
Example 4: Remove duplicates, keep the order · 3 marks · Short answerHarder board level
Write a function unique(L) that returns a new list containing each item of L once, in the order of first appearance, without changing L. Show the call for L = [3, 1, 3, 2, 1].
Try it first, then show the solutionSolution
- Start with an empty result and add an item only if it is not already there (membership with
not in). (1 mark) def unique(L): res = [] for x in L: if x not in res: res.append(x) return res L = [3, 1, 3, 2, 1] print(unique(L), L)- Loop and condition (1 mark); return of the new list (½ mark); L is untouched because only res is changed (½ mark).
Answer: [3, 1, 2] [3, 1, 3, 2, 1]
Example 5: Negative-step slice and slice assignment · 2 marks · Short answerHOTS / competency
Predict the output:
L = [10, 20, 30, 40, 50, 60]
print(L[-2:0:-2])
L[1:3] = [5]
print(L, L[::3])Try it first, then show the solutionSolution
- L[-2:0:-2] starts at index -2 (that is 4, value 50) and moves left by 2: index 2 (30); index 0 is the stop and is left out. (1 mark)
- L[1:3] = [5] replaces the two items 20 and 30 with one item 5: [10, 5, 40, 50, 60].
- L[::3] takes indexes 0 and 3: [10, 50]. (1 mark)
Answer: [50, 30]
[10, 5, 40, 50, 60] [10, 50]
Example 6: Case study: a marks list · 4 marks · Case-basedHOTS / competency
Suppose a teacher stores the marks of a group in M = [78, 91, 66, 91, 85].
(i) Write one statement to display the highest mark and how many students scored it. (1 mark)
(ii) Write one statement to create D, the marks in descending order, without changing M. (1 mark)
(iii) A helper writes T = M and then T.remove(66). What is M now, and why? (2 marks)
Try it first, then show the solutionSolution
- (i)
print(max(M), M.count(max(M)))gives 91 2. - (ii)
D = sorted(M, reverse=True)gives [91, 91, 85, 78, 66] and leaves M alone; M.sort() would change M. - (iii) T = M creates an alias, not a copy, so remove() changes the one list both names share.
M = [78, 91, 66, 91, 85] print(max(M), M.count(max(M))) D = sorted(M, reverse=True) print(D) T = M T.remove(66) print(M)
Answer: (i) 91 2 (ii) D = sorted(M, reverse=True) → [91, 91, 85, 78, 66] (iii) M becomes [78, 91, 91, 85], because T and M name the same list.
Where students lose marks in List Methods and Operations
The slips examiners see most often, and what to write instead.
Mistake: Counting an appended list as several items
append() adds its argument as a single item, even when the argument is a list.
Wrong working
L = [1, 2]; L.append([3, 4]) → [1, 2, 3, 4], len 4
Right working
L = [1, 2]; L.append([3, 4]) → [1, 2, [3, 4]], len 3
Do this: Use extend() to add the items separately; with append() expect a nested list.
Usually costs: The full mark of a 1-mark output question.
Mistake: Assigning the result of sort() or reverse()
These methods change the list and return None.
Wrong working
L = L.sort()
print(L) # prints NoneRight working
L.sort()
print(L)Do this: Call the method on its own line, or use sorted(L) when a new list is needed.
Usually costs: Half to 1 mark in a program.
Mistake: Treating M = L as a copy
Both names refer to the same list, so changes through one show through the other.
Wrong working
M = L
M.remove(66) # 'L is unchanged'Right working
M = L[:] # or list(L)
M.remove(66) # L is unchangedDo this: Copy with [:] or list() whenever the original must stay as it is.
Usually costs: 1 mark in output and case questions.
Mistake: Including the stop index of a slice
A slice stops just before the stop index, in either direction.
Wrong working
[10, 20, 30, 40][1:3] → [20, 30, 40]
Right working
[10, 20, 30, 40][1:3] → [20, 30]
Do this: List the indexes visited and cross out the stop index before writing the answer.
Usually costs: 1 mark.
Exam tips
- In output questions, write lists exactly as Python prints them: [1, 2, 3] with a space after each comma and quotes around strings, for example ['a', 'b'].
- The 2026-27 sample paper's first question is the output of an insert() call, and its error-finding question prints a list in reverse with a range() mistake; both are standard list traps.
- When asked to write a function, return a new list if the question says 'returns a new list'; do not change the parameter in place.
- If remove() or index() is used on a value that may be absent, check with
infirst; the exam expects you to know these raise ValueError. - For 'mutable versus immutable' MCQs: list and dictionary are mutable; int, float, string and tuple are immutable.
Practice questions on List Methods and Operations
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
Which list method adds each element of another sequence to the end of a list as separate items?
(a) append() (b) insert() (c) extend() (d) add()Hint
One method swallows, the other spills.
Answer
(c) extend()
Q2 · 1 mark · Very short answerBoard level
Write the output:
L = [2, 4, 6, 8] print(L[1:3] * 2, 6 in L)Hint
The slice stops before index 3.
Answer
[4, 6, 4, 6] True
Q3 · 1 mark · Very short answerBoard level
Write the output:
L = [5, 2, 8] X = L.sort() print(X, L)Hint
What does sort() return?
Answer
None [2, 5, 8]
Q4 · 1 mark · Very short answerHarder board level
Write the output:
L = [1, 2, 3, 2] L.remove(2) print(L, L.index(2))Hint
remove() deletes only the first match.
Answer
[1, 3, 2] 2
Q5 · 3 marks · Short answerHarder board level
Write a function split_even_odd(L) that returns two new lists, the even numbers and the odd numbers of L, in their original order. Show the output of print(split_even_odd([7, 12, 5, 8, 3])).
Hint
Two empty lists, one loop, one if-else; return both.
Answer
def split_even_odd(L): ev, od = [], [] for x in L: if x % 2 == 0: ev.append(x) else: od.append(x) return ev, od print(split_even_odd([7, 12, 5, 8, 3]))Output: ([12, 8], [7, 5, 3]) (two returned values come back as a tuple).
Q6 · 1 mark · Assertion-reasonHarder board level
Assertion (A): After M = L, the statement M.append(5) also changes L.
Reason (R): The assignment M = L creates a separate copy of the list L.
(a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.Hint
Is it a copy or a second name?
Answer
(c) A is true but R is false: M = L makes an alias (one list, two names), which is exactly why L changes.
Q7 · 2 marks · Short answerHOTS / competency
Predict the output and explain the second item:
def change(L): L[0] = 99 L = [1, 2] L.append(3) A = [5, 6] change(A) print(A)Hint
After L = [1, 2], whose list does L refer to?
Answer
[99, 6]. L[0] = 99 changes the caller's list. Then L = [1, 2] makes the local name refer to a new list, so append(3) changes only that new list, not A.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What does L.append([7, 8]) add to L?Show answer
One item, the list [7, 8].
2.Which list method returns the item it removes?Show answer
pop().
3.What is the difference between sort() and sorted()?Show answer
L.sort() changes L and returns None; sorted(L) returns a new sorted list and leaves L unchanged.
4.What does [1, 2] + (3,) give?Show answer
TypeError: can only concatenate list (not "tuple") to list. A list can be joined only to another list.
5.How do you make an independent copy of L?Show answer
M = L[:] or M = list(L).
6.What does [5, 6, 7].index(9) do?Show answer
Raises ValueError, because 9 is not in the list.
List Methods and Operations: frequently asked questions
What is the difference between append() and extend() in Python?
append(x) adds x to the end as a single item, so appending a list creates a nested list. extend(seq) adds each item of the sequence separately. After L = [1]; L.append([2, 3]) the list is [1, [2, 3]]; after L.extend([2, 3]) it is [1, 2, 3].
Why does print(L.sort()) print None?
sort() rearranges the list in place and returns None, so print shows None. Print L on the next line, or use print(sorted(L)) to get a new sorted list.
Are Class XI list topics asked in the Class 12 board exam?
Yes. The CBSE Class 12 syllabus begins with a revision of Class XI Python, and every recent sample paper has list output, error-finding or function questions.
Which list functions and methods are in the syllabus?
len(), list(), append(), extend(), insert(), count(), index(), remove(), pop(), reverse(), sort(), sorted(), min(), max() and sum(), along with indexing, slicing, concatenation, repetition, membership, traversal and nested lists.
Does slicing a list ever give an IndexError?
No. A slice whose limits go past the end simply stops at the end, for example [1, 2, 3][1:10] gives [2, 3]. Indexing a single position past the end, such as [1, 2, 3][5], does raise IndexError.