Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Tutorial
  3. Python List Methods: append, insert, remove, sort, and More

Data structures · Tutorial 15

Python List Methods: append, insert, remove, sort, and More

Modify lists with append, extend, insert, remove, pop, sort, reverse, and understand which methods return None.

Open the compilerPractice exercises
beginner8 min readUpdated November 19, 20263 learning goals
On this page
  1. Adding items
  2. Removing items
  3. Finding items
  4. Sorting
  5. Reversing
  6. Joining and splitting
  7. A complete example
  8. Practice

What you will learn

  • Add and remove list items safely
  • Sort lists in place and with sorted()
  • Avoid the common append-versus-extend mistake
Before this lesson: Python Lists: Creation, Indexing, and Iteration

Lists provide methods that change the list in place. Most of them return None, so assigning their result to a variable is a common mistake.

Adding items#

Python
items = ["a", "b"]

items.append("c")        # add one item at the end
items.extend(["d", "e"]) # add every item from another iterable
items.insert(0, "start") # insert at a position

print(items)
Expected output

['start', 'a', 'b', 'c', 'd', 'e']

append(["d", "e"]) would add the entire list as a single nested item. Use extend() to add the elements individually.

Removing items#

Python
items = ["a", "b", "c", "b"]

items.remove("b")        # remove the first matching value
last = items.pop()       # remove and return the last item
first = items.pop(0)     # remove and return the item at index 0
items.clear()            # remove every item

print(last, first)
Expected output

b a

remove() raises ValueError if the value is absent. pop() raises IndexError when the list is empty or the index is invalid. Check with in or handle the exception when absence is possible.

Finding items#

Python
items = ["a", "b", "c", "b"]

print(items.index("b"))    # 1: first occurrence
print(items.count("b"))    # 2

Both methods raise or return zero based on the data; index() raises ValueError when the value is missing.

Sorting#

Python
numbers = [4, 1, 3, 2]

numbers.sort()             # in place
print(numbers)             # [1, 2, 3, 4]

numbers.sort(reverse=True)
print(numbers)             # [4, 3, 2, 1]

words = ["banana", "apple", "cherry"]
print(sorted(words, key=len))  # ['apple', 'banana', 'cherry']

sort() modifies the list and returns None. sorted() returns a new list and leaves the original unchanged. Both are stable, so equal elements keep their relative order.

Sorting mixed types such as integers and strings raises TypeError on Python 3. Convert to a common key first.

Reversing#

Python
values = [1, 2, 3]
values.reverse()
print(values)       # [3, 2, 1]

copy = values[::-1] # new reversed list

Again, reverse() changes the original and returns None.

Joining and splitting#

Lists and strings meet through join() and split():

Python
words = ["Python", "is", "readable"]
sentence = " ".join(words)
print(sentence)     # Python is readable

parts = sentence.split()
print(parts)        # ['Python', 'is', 'readable']

join() is a string method. Every item must be a string; convert numbers with map(str, numbers) first.

Mutating while iterating

Removing items from a list while looping over it can skip elements. Iterate over a copy (for item in items[:]:) or build a new filtered list instead.

A complete example#

Python
scores = [88, 92, 79, 92, 65]

scores.append(100)
scores.remove(65)
scores.sort(reverse=True)

print(scores)
print("Highest:", scores[0])
print("Count of 92:", scores.count(92))
print("Average:", sum(scores) / len(scores))

Practice#

Start with an empty shopping list. Add three items, insert one at the front, remove one by name, and sort the result alphabetically. Print the list after each step so you can see the effect of each method.

Previous tutorialPython Lists: Creation, Indexing, and IterationNext tutorialPython Tuples: Immutable Sequences and Unpacking

Related tutorials

beginner

Python Tuples: Immutable Sequences and Unpacking

Use tuples for fixed groups of values, unpack them cleanly, and know when a tuple is a better choice than a list.

7 min read
beginner

Python Dictionaries: Keys, Values, and Practical Patterns

Store and retrieve key-value data with dictionaries, iterate over items, and use get, update, and comprehensions.

9 min read

On this page

  1. Adding items
  2. Removing items
  3. Finding items
  4. Sorting
  5. Reversing
  6. Joining and splitting
  7. A complete example
  8. Practice

Run the examples

Every Python block has a Run in compiler button that opens the code in a new tab.