list.insert()

list.insert(i, x)
Returns: None · Updated March 14, 2026 · List Methods
lists methods mutation

The .insert() method adds an element to a list at a specified index. Unlike .append() which always adds to the end, .insert() gives you precise control over where the new element lands. The list is modified in-place and the method returns None.

Syntax

list.insert(i, x)

Parameters

ParameterTypeDefaultDescription
iintThe index at which to insert the element. Can be positive or negative.
xanyThe element to insert. Can be of any type.

Examples

Basic usage — insert at the beginning

Insert an element at index 0:

numbers = [1, 2, 3]
numbers.insert(0, 0)
print(numbers)
# [0, 1, 2, 3]

Insert in the middle

Insert an element at a specific position:

letters = ["a", "b", "d", "e"]
letters.insert(2, "c")
print(letters)
# ['a', 'b', 'c', 'd', 'e']

Insert at the end

Using a large index or len() places the element at the end:

fruits = ["apple", "banana"]
fruits.insert(len(fruits), "cherry")
print(fruits)
# ['apple', 'banana', 'cherry']

Negative indices

Negative indices count from the end:

items = [1, 2, 3, 4]
items.insert(-1, "middle")
print(items)
# [1, 2, 3, 'middle', 4]

items.insert(-2, "second-last")
print(items)
# [1, 2, 3, 'second-last', 'middle', 4]

Inserting different types

Python lists are heterogeneous — you can insert any object:

mixed = [1, 2]
mixed.insert(0, "string")
mixed.insert(1, 3.14)
mixed.insert(2, ["a", "list"])
print(mixed)
# ['string', 3.14, ['a', 'list'], 1, 2]

Common Patterns

Building a sorted list incrementally

When you need to maintain sorted order as you add elements:

sorted_nums = [1, 5, 10]
new = 7

import bisect
sorted_nums.insert(bisect.bisect(sorted_nums, new), new)
print(sorted_nums)
# [1, 5, 7, 10]

For frequent sorted insertions, consider using bisect from the standard library.

Inserting at a known position

A common pattern when you know exactly where to insert:

document = ["Paragraph 1", "Paragraph 3"]
document.insert(1, "Paragraph 2")
print(document)
# ['Paragraph 1', 'Paragraph 2', 'Paragraph 3']

Prepending to create a new list

If you need to add multiple elements at the start:

result = [3, 4, 5]
result.insert(0, 2)
result.insert(0, 1)
result.insert(0, 0)
print(result)
# [0, 1, 2, 3, 4, 5]

This is less efficient than concatenating or using a deque for bulk operations.

Inserting None as a sentinel

Sometimes used to mark positions:

data = ["a", "b", "c"]
data.insert(1, None)
print(data)
# ['a', None, 'b', 'c']

Performance Note

  • Inserting at the end: O(1)
  • Inserting at the beginning or middle: O(n) — requires shifting elements

For frequent insertions at the beginning, consider using collections.deque:

from collections import deque

dq = deque(["b", "c"])
dq.appendleft("a")
print(list(dq))
# ['a', 'b', 'c']

See Also