Python Lists: How to Add Elements to a List
Learn every way to add elements to a Python list: append, extend, insert, the + operator, and slice assignment — with examples and gotchas explained.
Python lists are mutable sequences, which means you can add, remove, and modify elements after the list has been created. This chapter covers every method and operator Python provides for inserting new elements into a list, explains when to use each one, and highlights the most common gotchas.
Methods and operators at a glance
| Approach | Adds | Position | Modifies in place? |
|---|---|---|---|
list.append(x) | one item | end | yes |
list.extend(iterable) | all items from iterable | end | yes |
list.insert(i, x) | one item | index i | yes |
list + other | all items from other | end | no (returns new list) |
list += other | all items from other | end | yes |
list[i:i] = items | multiple items | index i | yes |
Using append()
append() adds a single element to the end of a list. It modifies the list in place and always returns None.
append() accepts any Python object — strings, integers, booleans, and even other lists:
nums = [1, 2, 3]
nums.append(4)
print(nums) # [1, 2, 3, 4]Gotcha: appending a list nests it
If you pass a list to append(), Python treats that list as a single element and creates a nested list — it does not merge the two lists together:
fruits = ['apple', 'banana']
fruits.append(['grape', 'kiwi'])
print(fruits) # ['apple', 'banana', ['grape', 'kiwi']]
print(len(fruits)) # 3, not 4To merge two lists instead, use extend() or the + operator (covered below).
Using extend()
extend() iterates over an iterable — a list, tuple, set, or any other sequence — and appends each of its items to the end of the list:
append() vs extend() — side by side
a = [1, 2, 3]
a.extend([4, 5])
print(a) # [1, 2, 3, 4, 5]
b = [1, 2, 3]
b.append([4, 5])
print(b) # [1, 2, 3, [4, 5]] ← nested!Gotcha: extending with a string
Strings are iterable, so extend() will add each character as a separate element:
letters = ['a', 'b']
letters.extend('cd')
print(letters) # ['a', 'b', 'c', 'd']If you want to add the whole string as one element, use append() instead.
Using insert()
insert(i, x) adds element x at position i, shifting all existing elements from that index onward one place to the right:
Prepending to a list (adding at the very beginning) is a common use case:
fruits = ['banana', 'orange']
fruits.insert(0, 'apple')
print(fruits) # ['apple', 'banana', 'orange']Gotcha: index beyond the list length
If the index you pass is larger than the current length of the list, Python does not raise an error — it simply appends the element to the end:
fruits = ['apple', 'banana']
fruits.insert(100, 'orange')
print(fruits) # ['apple', 'banana', 'orange']Negative indices work too: insert(-1, x) inserts just before the last element.
Using the + operator
The + operator concatenates two lists and returns a new list. Neither of the original lists is modified:
a = [1, 2, 3]
b = [4, 5, 6]
c = a + b
print(c) # [1, 2, 3, 4, 5, 6]
print(a) # [1, 2, 3] — unchangedUse + when you need to keep the originals intact, or when you are building a list expression rather than mutating one.
Using += (augmented assignment)
The += operator is shorthand for extend() — it merges the right-hand iterable into the existing list in place:
a = [1, 2, 3]
a += [7, 8]
print(a) # [1, 2, 3, 7, 8]Unlike +, += does not create a new list — it updates a in place, which is more memory-efficient when working with large lists.
Inserting multiple items at a specific position (slice assignment)
For inserting a block of elements in the middle of a list, slice assignment is the most direct approach:
nums = [1, 2, 5, 6]
nums[2:2] = [3, 4] # insert [3, 4] starting at index 2
print(nums) # [1, 2, 3, 4, 5, 6]The syntax list[i:i] = items opens a zero-width window at index i and fills it with the elements from items. No existing items are removed.
Choosing the right method
- Add one item at the end: use
append(). It is the simplest and fastest option for single-element insertion. - Merge another list into this one: use
extend()or+=. Both are equivalent;+=is slightly more idiomatic in loops. - Add one item at a specific position: use
insert(). - Need the original list untouched: use the
+operator and assign the result to a new variable. - Insert several items in the middle: use slice assignment.
Related chapters
- Python Lists — creating lists, indexing, and list properties
- Access List Items — reading elements by index and slice
- Change List Items — updating existing elements in place
- Remove List Items — deleting elements with
remove(),pop(), anddel - List Methods — full reference for all built-in list methods