Python List Methods Cheat Sheet
Quick reference guide for Python list operations. Master appending, inserting, removing, sorting, and slicing elements.
Modifying List Elements
Methods to add, update, or remove items in a list.
| Method | Syntax | Description |
|---|---|---|
| append() | my_list.append(item) | Adds an element to the end of the list. |
| extend() | my_list.extend(iterable) | Appends all elements of an iterable to the list. |
| insert() | my_list.insert(index, item) | Inserts an element at a specified position. |
| remove() | my_list.remove(item) | Removes the first occurrence of the specified item. Raises ValueError if not found. |
| pop() | my_list.pop([index]) | Removes and returns the item at the specified index (defaults to last item). |
List Utility & Order
Methods for searching, sorting, and copying lists.
| Method | Syntax | Description |
|---|---|---|
| sort() | my_list.sort(reverse=False, key=None) | Sorts the list in-place. |
| reverse() | my_list.reverse() | Reverses the order of list elements in-place. |
| index() | my_list.index(item) | Returns the index of the first occurrence of the specified item. |
| clear() | my_list.clear() | Removes all elements from the list. |
Frequently Asked Questions
What is the difference between append() and extend()?
append() adds its argument as a single element to the end of a list, whereas extend() iterates over its argument and adds each element separately.
How do you reverse a list without modifying it?
Use the reversed() function, or use list slicing: my_list[::-1].
Keep Learning
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Lists
Learn everything about Python lists. Discover how to create, slice, modify, and iterate through arrays in Python natively.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.