← All references
List Methods
list.append(x) / list.pop() / list.sort() / list.reverse()Operations on lists (mutable sequences).
List Methods
Lists are mutable — methods modify in place (unless noted).
| Method | Effect |
|---|---|
.append(x) | Add x at end |
.pop(i=-1) | Remove & return item at i |
.sort() | Sort in place |
.reverse() | Reverse in place |
.extend(iter) | Append all items from iter |
.insert(i, x) | Insert x at position i |
Example
fruits = ["apple", "banana"]\nfruits.append("cherry")\nprint(fruits)\nfruits.sort()\nprint(fruits)\nlast = fruits.pop()\nprint("Popped:", last)\nprint(fruits)