A list is Python’s most used collection: an ordered, changeable sequence that grows and shrinks as needed. It replaces most uses of arrays in C, without fixed sizes or manual memory management.
What a list is
Ordered: items keep their positions, indexed from 0.
Mutable: items can be changed, added and removed after creation.
Heterogeneous: one list can mix types, e.g. ['cat', 87.23, 65, [9, 8, 1]].
Duplicates allowed: [1, 1, 2] is fine.
Create lists with brackets ([] is empty) or with list(iterable): list("abc") gives ['a', 'b', 'c'].
Indexing, slicing and operators
Lists support the same indexing and slicing as strings (nums[0], nums[-1], nums[1:3], nums[:]). An index beyond the end raises IndexError: list index out of range. Unlike strings, items can be assigned: nums[1] = 99.
Operation
Example
Result
+ join
[1, 2] + [3]
[1, 2, 3]
* repeat
['pass'] * 3
['pass', 'pass', 'pass']
== compare
[1, 2] == [1, 2]
True
in / not in
2 in [1, 2, 3]
True
List methods
Method
Effect
Returns
append(x)
Add x at the end
None
extend(iterable)
Add every item of the iterable at the end
None
insert(i, x)
Insert x before index i (at the end if i is past the end)
None
remove(x)
Remove the first x (ValueError if absent)
None
pop() / pop(i)
Remove and return the last item / item at i
The removed item
index(x)
Position of the first x (ValueError if absent)
An int
count(x)
Number of times x occurs
An int
sort()
Sort in place (reverse=True for descending)
None
reverse()
Reverse in place
None
copy()
Shallow copy
A new list
clear()
Remove all items
None
del nums[i] and del nums[i:j] delete by position. Built-in functions that accept lists include len(), sum(), min(), max(), sorted() (returns a new sorted list), any() (true if at least one item is truthy) and all() (true if every item is truthy).
Aliasing versus copying
This is called aliasing: two names referring to one mutable object.
Nested lists
A list can contain lists, which gives a table (a matrix): asia[0][1] is row 0, column 1.
Key takeaways
Lists are ordered, mutable, heterogeneous and allow duplicates.
Index and slice like strings; assign to items to change them.
In-place methods (append, sort, reverse, remove) return None; sorted() returns a new list.
Use .copy() or [:] to copy; plain assignment aliases.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain the difference between numlist.sort() and sorted(numlist), with an example.
Show worked answer
numlist.sort() is a list method that rearranges the original list in place and returns None. sorted(numlist) is a built-in function that leaves the original unchanged and returns a new sorted list; it also works on any iterable (tuples, strings, sets, dictionary keys). Example: with n = [3, 1, 2], s = sorted(n) gives s = [1, 2, 3] while n stays [3, 1, 2]; after n.sort(), n itself becomes [1, 2, 3].
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-structures-and-control-statements-in-python/lists/ to read this page.