← Back to Chapters

Python List Methods

? Python List Methods

⚡ Quick Overview

Python lists come with many built-in methods that let you add, remove, search, copy, and reorder elements easily. Mastering these methods makes your code shorter, cleaner, and easier to read.

In this page, you'll learn the most commonly used list methods such as append(), insert(), remove(), pop(), clear(), copy(), extend(), count(), index(), sort(), and reverse().

? Key Concepts

  • Mutability: Lists are mutable, so methods usually change the original list.
  • In-place operations: Methods like append(), insert(), remove(), pop(), clear(), sort(), and reverse() modify the list directly.
  • Non-in-place behavior: copy() returns a new list.
  • Searching: count() and index() help find elements.
  • Combining lists: extend() adds multiple elements from another iterable.

? Syntax and Theory

Each list method is called using the dot notation on a list object:

list_name.method_name(arguments)
  • append(x) → add a single item x at the end.
  • insert(i, x) → insert x at index i.
  • remove(x) → remove the first occurrence of x.
  • pop(i) → remove and return the item at index i (last item if i is not given).
  • clear() → remove all items from the list.
  • copy() → return a shallow copy of the list.
  • extend(iterable) → add all elements from another iterable.
  • count(x) → return how many times x appears.
  • index(x) → return the index of the first occurrence of x.
  • sort() → sort the list in place (ascending by default).
  • reverse() → reverse the elements in place.

? Code Examples

? append()

Adds an item to the end of the list.

? View Code Example
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)

➕ insert()

Inserts an item at a specified position.

? View Code Example
fruits = ["apple", "banana"]
fruits.insert(1, "orange")
print(fruits)

➖ remove()

Removes the first occurrence of the specified item.

? View Code Example
fruits = ["apple", "banana", "cherry"]
fruits.remove("banana")
print(fruits)

✂️ pop()

Removes an item at the given position. If no index is specified, removes the last item.

? View Code Example
fruits = ["apple", "banana", "cherry"]
fruits.pop(1)
print(fruits)

?️ clear()

Removes all items from the list.

? View Code Example
fruits = ["apple", "banana", "cherry"]
fruits.clear()
print(fruits)

? copy()

Returns a shallow copy of the list.

? View Code Example
fruits = ["apple", "banana"]
new_list = fruits.copy()
print(new_list)

? extend()

Adds elements of another list (or iterable) to the current list.

? View Code Example
fruits = ["apple", "banana"]
more = ["cherry", "mango"]
fruits.extend(more)
print(fruits)

? count()

Returns the number of times a specified value appears in the list.

? View Code Example
numbers = [1, 2, 2, 3, 4, 2]
print(numbers.count(2))

? index()

Returns the index of the first occurrence of a specified value.

? View Code Example
fruits = ["apple", "banana", "cherry"]
print(fruits.index("banana"))

⬆️ sort()

Sorts the list in ascending order by default.

? View Code Example
numbers = [3, 1, 4, 2]
numbers.sort()
print(numbers)

? reverse()

Reverses the order of the list.

? View Code Example
numbers = [1, 2, 3, 4]
numbers.reverse()
print(numbers)

? Live Output and Explanation

  • append()["apple", "banana", "cherry"]
  • insert(1, "orange")["apple", "orange", "banana"]
  • remove("banana")["apple", "cherry"]
  • pop(1) on ["apple", "banana", "cherry"] removes "banana" and prints ["apple", "cherry"].
  • clear() → the list becomes [].
  • copy() → creates a new list with the same elements as the original.
  • extend(["cherry", "mango"])["apple", "banana", "cherry", "mango"].
  • count(2) in [1, 2, 2, 3, 4, 2]3.
  • index("banana") in ["apple", "banana", "cherry"]1.
  • sort() on [3, 1, 4, 2][1, 2, 3, 4].
  • reverse() on [1, 2, 3, 4][4, 3, 2, 1].

Try running each example in a Python shell or IDE to see the behavior yourself. Pay attention to which methods return values and which simply modify the list.

✅ Tips and Best Practices

  • Choose the right method depending on whether you need to add, remove, or modify elements.
  • Use copy() or slicing (new_list = old_list[:]) to avoid modifying the original list accidentally.
  • Remember that methods like sort() and reverse() modify the list in place and return None.
  • Use pop() when you need both to remove an element and to use its value.
  • Check that a value exists in the list (e.g. using if x in my_list:) before calling remove() or index() to avoid errors.

? Try It Yourself

  • Create a list of your favorite movies and use append() and insert() to add more titles.
  • Use remove() and pop() to delete specific items and display what was removed.
  • Use extend() to merge two lists, such as fruits and vegetables.
  • Practice with count() and index() on a list with duplicate values.
  • Sort a list of numbers with sort() and then reverse it with reverse().
  • Make a copy of a list using copy(), modify the copy, and verify that the original list is unchanged.