PYnative

Practice Coding

  • Python â–¼
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Coding Exercises â–¼
    • Python Exercises
    • C++ Exercises
    • C Programming Exercises
    • Java Exercises
    • C# Exercises
  • MCQsâ–¼
    • Python MCQ Quizzes
    • Java MCQ Quizzes
    • C++ MCQ Quizzes
  • Compilersâ–¼
    • Online Python Compiler
    • Online C Compiler
    • Online C++ Compiler
    • Online Java Compiler
    • Online C# Compiler
Home » Python » Basics » Python List Methods: All 11 Methods With Examples

Python List Methods: All 11 Methods With Examples

Updated on: December 4, 2026 | Leave a Comment

A Python list is an ordered, changeable collection of items. Lists have 11 built-in methods that let you add, remove, find, count, sort, reverse, and copy items. Because lists are mutable, most of these methods change the list in place instead of creating a new one, which is the single most important thing to remember when using them.

In this tutorial, you’ll learn every list method with examples, see which built-in functions complement them, and avoid the mistakes that trip up beginners.

Key terms used in this article:

  • List: An ordered, mutable sequence written with square brackets, such as [1, 2, 3].
  • Mutable: Can be changed after it’s created.
  • In place: The method changes the original list and returns None, instead of returning a new list.
  • Index: The position of an item. The first item is at index 0, and the last is at -1.

Table of contents

  • List methods at a glance
  • Adding items to a list
    • append()
    • extend()
    • append() vs. extend() vs. +
    • insert()
  • Removing items from a list
    • remove()
    • pop()
    • clear()
    • The del statement
    • Which removal tool should you use?
  • Finding and counting items
    • index()
    • count()
  • Sorting and reversing
    • sort()
    • Sorting with a key function
    • sort() vs. sorted()
    • reverse()
  • Copying a list
    • copy()
    • Shallow copy vs. deep copy
  • Built-in functions that work with lists
  • Performance of list methods
  • Real-world example: a simple to-do manager
  • Common mistakes
  • Practice exercises
  • Summary

List methods at a glance

MethodDescriptionReturns
append(item)Adds one item to the endNone
extend(iterable)Adds every item from an iterable to the endNone
insert(index, item)Inserts an item at a given positionNone
remove(item)Removes the first matching itemNone
pop(index=-1)Removes and returns the item at an index (the last item by default)The removed item
clear()Removes all itemsNone
index(item, start, end)Returns the index of the first matching itemint
count(item)Counts how many times an item appearsint
sort(key=None, reverse=False)Sorts the list in placeNone
reverse()Reverses the list in placeNone
copy()Returns a shallow copy of the listNew list

You can list them from Python with [m for m in dir(list) if not m.startswith("_")].

Adding items to a list

append()

append() adds a single item to the end of the list:

fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)

fruits.append(["kiwi", "mango"])  # adds the whole list as ONE item
print(fruits)
print(len(fruits))Code language: Python (python)

Output:

['apple', 'banana', 'cherry']
['apple', 'banana', 'cherry', ['kiwi', 'mango']]
4

append() is the fastest way to grow a list. Building a list in a loop usually looks like this:

squares = []
for n in range(1, 6):
    squares.append(n * n)
print(squares)Code language: Python (python)

Output:

[1, 4, 9, 16, 25]

extend()

extend() adds each item from an iterable (a list, tuple, string, set, range, and so on):

fruits = ["apple", "banana"]
fruits.extend(["kiwi", "mango"])
print(fruits)

fruits.extend(("fig",))
print(fruits)

letters = ["a"]
letters.extend("bcd")  # a string is iterable, so each character is added
print(letters)Code language: Python (python)

Output:

['apple', 'banana', 'kiwi', 'mango']
['apple', 'banana', 'kiwi', 'mango', 'fig']
['a', 'b', 'c', 'd']

append() vs. extend() vs. +

a = [1, 2]
a.append([3, 4])
print(a)

b = [1, 2]
b.extend([3, 4])
print(b)

c = [1, 2]
d = c + [3, 4]   # creates a NEW list
print(c, d)

e = [1, 2]
e += [3, 4]      # same as extend(): changes e in place
print(e)Code language: Python (python)

Output:

[1, 2, [3, 4]]
[1, 2, 3, 4]
[1, 2] [1, 2, 3, 4]
[1, 2, 3, 4]

insert()

insert(index, item) puts an item before the given index:

colors = ["red", "green", "blue"]

colors.insert(1, "yellow")
print(colors)

colors.insert(0, "black")   # at the start
print(colors)

colors.insert(len(colors), "white")  # at the end, like append()
print(colors)

colors.insert(100, "pink")  # index past the end: added at the end
print(colors)Code language: Python (python)

Output:

['red', 'yellow', 'green', 'blue']
['black', 'red', 'yellow', 'green', 'blue']
['black', 'red', 'yellow', 'green', 'blue', 'white']
['black', 'red', 'yellow', 'green', 'blue', 'white', 'pink']

Inserting near the start of a long list is slow, because every item after it has to move. If you often add items at the front, use collections.deque and its appendleft() method.

Removing items from a list

remove()

remove(item) deletes the first item equal to the value. It raises ValueError if the item isn’t in the list:

pets = ["cat", "dog", "parrot", "dog"]
pets.remove("dog")
print(pets)

try:
    pets.remove("hamster")
except ValueError as error:
    print("Error:", error)

# Safe removal
if "hamster" in pets:
    pets.remove("hamster")Code language: Python (python)

Output:

['cat', 'parrot', 'dog']
Error: list.remove(x): x not in list

To remove every occurrence of a value, build a new list with a comprehension:

numbers = [1, 2, 3, 2, 4, 2]
numbers = [n for n in numbers if n != 2]
print(numbers)Code language: Python (python)

Output:

[1, 3, 4]

pop()

pop() removes an item by index and returns it. Without an argument, it removes the last item:

stack = ["a", "b", "c", "d"]

last = stack.pop()
print(last, stack)

first = stack.pop(0)
print(first, stack)

try:
    [].pop()
except IndexError as error:
    print("Error:", error)Code language: Python (python)

Output:

d ['a', 'b', 'c']
a ['b', 'c']
Error: pop from empty list

pop() from the end is fast, which makes a list a good stack (last in, first out):

history = []
history.append("page1")
history.append("page2")
history.append("page3")

print("Back to:", history.pop())
print("Back to:", history.pop())
print(history)Code language: Python (python)

Output:

Back to: page3
Back to: page2
['page1']

clear()

clear() empties the list but keeps the same list object:

cart = ["pen", "book"]
alias = cart
cart.clear()
print(cart, alias)  # both names see the empty listCode language: Python (python)

Output:

[] []

The del statement

del isn’t a method, but it’s the other common way to remove items, including whole slices:

nums = [0, 1, 2, 3, 4, 5, 6]
del nums[0]
print(nums)
del nums[1:3]
print(nums)
del nums[::2]
print(nums)Code language: Python (python)

Output:

[1, 2, 3, 4, 5, 6]
[1, 4, 5, 6]
[4, 6]

Which removal tool should you use?

You want toUse
Remove by valueremove(value)
Remove by index and get the itempop(index)
Remove by index or slice, without getting the itemdel lst[i] or del lst[a:b]
Remove every matching valueA list comprehension
Remove everythingclear()

Finding and counting items

index()

index(item) returns the position of the first match, and raises ValueError if the item isn’t found. Optional start and end arguments limit the search:

letters = ["a", "b", "c", "b", "a"]

print(letters.index("b"))
print(letters.index("b", 2))   # search from index 2

try:
    letters.index("z")
except ValueError as error:
    print("Error:", error)Code language: Python (python)

Output:

1
3
Error: 'z' is not in list

To find all positions of a value, use enumerate():

letters = ["a", "b", "c", "b", "a"]
positions = [i for i, ch in enumerate(letters) if ch == "b"]
print(positions)Code language: Python (python)

Output:

[1, 3]

count()

votes = ["yes", "no", "yes", "yes", "maybe"]
print(votes.count("yes"))
print(votes.count("abstain"))Code language: Python (python)

Output:

3
0

Calling count() for every distinct value is slow on large lists. Use collections.Counter to count everything in one pass:

from collections import Counter

votes = ["yes", "no", "yes", "yes", "maybe"]
print(Counter(votes))
print(Counter(votes).most_common(1))Code language: Python (python)

Output:

Counter({'yes': 3, 'no': 1, 'maybe': 1})
[('yes', 3)]

Sorting and reversing

sort()

sort() sorts the list in place in ascending order. Use reverse=True for descending order:

numbers = [42, 7, 19, 3, 25]
numbers.sort()
print(numbers)

numbers.sort(reverse=True)
print(numbers)

names = ["kelly", "Emma", "adam", "Brad"]
names.sort()
print(names)  # uppercase letters sort before lowercaseCode language: Python (python)

Output:

[3, 7, 19, 25, 42]
[42, 25, 19, 7, 3]
['Brad', 'Emma', 'adam', 'kelly']

Sorting with a key function

The key argument takes a function that’s called on each item. The list is sorted by the values it returns:

names = ["kelly", "Emma", "adam", "Brad"]

names.sort(key=str.lower)        # case-insensitive
print(names)

names.sort(key=len)              # by length
print(names)

students = [("Jessa", 88), ("Kelly", 95), ("Emma", 79)]
students.sort(key=lambda s: s[1], reverse=True)
print(students)Code language: Python (python)

Output:

['adam', 'Brad', 'Emma', 'kelly']
['adam', 'Brad', 'Emma', 'kelly']
[('Kelly', 95), ('Jessa', 88), ('Emma', 79)]

Python’s sort is stable: items that compare equal keep their original order. That lets you sort by several keys in steps, or return a tuple from the key function. See Lambda Functions in Python for more key examples.

Sorting a list that mixes incompatible types, such as numbers and strings, raises a TypeError.

sort() vs. sorted()

list.sort()sorted(iterable)
Works onLists onlyAny iterable
Changes the originalYesNo
ReturnsNoneA new sorted list
original = [3, 1, 2]
new_list = sorted(original)
print(original, new_list)

result = original.sort()
print(result, original)Code language: Python (python)

Output:

[3, 1, 2] [1, 2, 3]
None [1, 2, 3]

reverse()

reverse() flips the order of the list in place. It doesn’t sort:

items = [1, 5, 3, 9]
items.reverse()
print(items)

# Alternatives that create a new list or iterator
print(items[::-1])
print(list(reversed(items)))Code language: Python (python)

Output:

[9, 3, 5, 1]
[1, 5, 3, 9]
[1, 5, 3, 9]

Copying a list

copy()

Assigning a list to another variable doesn’t copy it. Both names point to the same list:

a = [1, 2, 3]
b = a          # same list
c = a.copy()   # new list

a.append(4)
print(a, b, c)Code language: Python (python)

Output:

[1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3]

copy(), list(a), and a[:] all create a shallow copy: a new outer list that holds the same inner objects.

Shallow copy vs. deep copy

For nested lists, a shallow copy still shares the inner lists. Use copy.deepcopy() to copy everything:

import copy

grid = [[1, 2], [3, 4]]
shallow = grid.copy()
deep = copy.deepcopy(grid)

grid[0][0] = 99
print(shallow)  # inner list is shared
print(deep)     # fully independentCode language: Python (python)

Output:

[[99, 2], [3, 4]]
[[1, 2], [3, 4]]

Built-in functions that work with lists

These aren’t list methods, but you’ll use them with lists all the time:

scores = [72, 88, 95, 61, 88]

print(len(scores))
print(sum(scores))
print(min(scores), max(scores))
print(sum(scores) / len(scores))
print(sorted(scores))
print(any(s > 90 for s in scores), all(s > 60 for s in scores))
print(list(enumerate(scores[:2])))
print(list(zip(["a", "b"], scores)))
print(88 in scores)Code language: Python (python)

Output:

5
404
61 95
80.8
[61, 72, 88, 88, 95]
True True
[(0, 72), (1, 88)]
[('a', 72), ('b', 88)]
True

Performance of list methods

OperationSpeed
append(), pop() from the endFast, constant time
lst[i] (read or write by index)Fast, constant time
insert(0, x), pop(0)Slow for long lists: every item moves
remove(), index(), count(), x in lstSlow for long lists: searches item by item
sort()O(n log n)

If you check membership often, convert the list to a set. If you add and remove at both ends, use collections.deque.

Real-world example: a simple to-do manager

todo = []

todo.append("Write report")
todo.append("Email client")
todo.insert(0, "Fix urgent bug")      # highest priority
todo.extend(["Book flights", "Pay bills"])
print("To-do:", todo)

done = todo.pop(0)
print("Completed:", done)

todo.remove("Book flights")
todo.sort()
print("Remaining (A-Z):", todo)
print("Position of 'Pay bills':", todo.index("Pay bills"))Code language: Python (python)

Output:

To-do: ['Fix urgent bug', 'Write report', 'Email client', 'Book flights', 'Pay bills']
Completed: Fix urgent bug
Remaining (A-Z): ['Email client', 'Pay bills', 'Write report']
Position of 'Pay bills': 1

Common mistakes

  • Assigning the result of an in-place method. numbers = numbers.sort() sets numbers to None. Call numbers.sort() on its own line, or use sorted().
  • Using append() when you mean extend(). a.append([3, 4]) adds a nested list.
  • Removing items while looping over the same list. This skips items. Loop over a copy or build a new list.
  • Thinking b = a copies a list. Use a.copy().
  • Calling remove() or index() without checking. Both raise ValueError when the item is missing.
# Bug: removing while iterating skips items
numbers = [2, 4, 5, 6, 8]
for n in numbers:
    if n % 2 == 0:
        numbers.remove(n)
print(numbers)  # 4 and 8 survived

# Fix: build a new list
numbers = [2, 4, 5, 6, 8]
numbers = [n for n in numbers if n % 2 != 0]
print(numbers)Code language: Python (python)

Output:

[4, 5, 8]
[5]

Practice exercises

Exercise 1: Remove duplicates from a list while keeping the original order.

items = [3, 1, 3, 2, 1, 4]
unique = []
for item in items:
    if item not in unique:
        unique.append(item)
print(unique)

# Shortcut: dict keys keep insertion order
print(list(dict.fromkeys(items)))Code language: Python (python)

Output:

[3, 1, 2, 4]
[3, 1, 2, 4]

Exercise 2: Move all zeros in a list to the end while keeping the order of the other items.

nums = [0, 3, 0, 1, 7, 0, 5]
result = [n for n in nums if n != 0]
result.extend([0] * nums.count(0))
print(result)Code language: Python (python)

Output:

[3, 1, 7, 5, 0, 0, 0]

Exercise 3: Sort a list of words by length, then alphabetically for words of the same length.

words = ["pear", "fig", "apple", "kiwi", "date", "plum"]
words.sort(key=lambda w: (len(w), w))
print(words)Code language: Python (python)

Output:

['fig', 'date', 'kiwi', 'pear', 'plum', 'apple']

Summary

  • Lists have 11 methods: append(), extend(), insert(), remove(), pop(), clear(), index(), count(), sort(), reverse(), and copy().
  • Most methods change the list in place and return None. Only pop(), index(), count(), and copy() return a value.
  • Use append() for one item and extend() for many. Use remove() to delete by value and pop() or del to delete by index.
  • Use sort() to sort in place and sorted() to get a new list. Pass key= to control the order.
  • b = a doesn’t copy a list. Use copy() for a shallow copy and copy.deepcopy() for nested lists.

Also, See:

  • Python Lists
  • List, Dict, and Set Comprehensions in Python
  • Python List Exercises
  • Python List Quiz

Filed Under: Python, Python Basics

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Basics

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises
Java Exercises
C# Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes

Leave a Reply Cancel reply

your email address will NOT be published. all comments are moderated according to our comment policy.

Use <pre> tag for posting code. E.g. <pre> Your entire code </pre>

In: Python Python Basics
TweetF  sharein  shareP  Pin

  Python Tutorials

  • Get Started with Python
  • Python Statements
  • Python Comments
  • Python Keywords
  • Python Variables
  • Python Operators
  • Python Data Types
  • Python Casting
  • Python Control Flow statements
  • Python For Loop
  • Python While Loop
  • Python Break and Continue
  • Python Nested Loops
  • Python Input and Output
  • Python range function
  • Check user input is String or Number
  • Accept List as a input from user
  • Python Numbers
  • Python Lists
  • Python Tuples
  • Python Sets
  • Python Dictionaries
  • Python Functions
  • Python Modules
  • Python isinstance()
  • Python OOP
  • Python Inheritance
  • Python Exceptions
  • Python Exercise for Beginners
  • Python Quiz for Beginners

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

  • Python Basics
  • Python Exercises
  • Python Quizzes
  • Python File Handling
  • Python Date and Time
  • Python OOP
  • Python Random
  • Python Regex
  • Python Pandas
  • Python Databases
  • Python MySQL
  • Python PostgreSQL
  • Python SQLite
  • Python JSON

About PYnative

PYnative.com is a platform built to help developers learn by doing. Solve coding exercises, take MCQs, and run code directly in built-in online compilers.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises
  • Java Exercises
  • C# Exercises

MCQ Quizzes

  • Python MCQs
  • Java MCQs
  • C++ MCQs

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2026 pynative.com