Changing a list (append, extend, insert, pop, sort)
A list can be changed in place: methods like append, extend, insert, pop and sort modify the same list and almost always return None.
Used in 75 lessons of the course, from 00.06.
A list is mutable: you can change it without building a new one.
append(x)adds one item at the end.extend(items)adds each item from another iterable.insert(i, x)putsxat positioni.pop()removes and returns the last item (or the one at the position you give).sort()sorts the list in place.
The key point: these methods change the original list. That is why append, extend, insert and sort return None: there is nothing new to hand back. Only pop returns something, the item it removed.
In the course you will see found.append(model_id) inside a loop: you start with an empty list and fill it up. It is a single line with no assignment, because the change happens to found.
found = []
found.append("a")
Reach for it when: you need to build or adjust a list step by step, for example collecting results inside a loop.
Examples
Common mistake
items = [3, 1, 2] items = items.sort() print(items)
Why: sort() sorts in place and returns None. By assigning it, you replace your list with None.
How to write it: Call items.sort() without assigning, or use sorted(items) if you want a new list.
Common mistake
items = [1, 2] items.append([3, 4]) print(items)
Why: append adds a single item: here, the whole list as one nested item.
How to write it: Use items.extend([3, 4]) to add each item separately.
