How to Append in Python: append() Explained With Examples
To append in Python, use the list.append() method. It adds one item to the end of a list, in place, and returns None. For example, after fruits = ["apple", "banana"], running fruits.append("cherry") changes the list to ["apple", "banana", "cherry"]. That one line is the answer most people are looking for, and the rest of this guide explains exactly how it works, what you can append, how it differs from extend() and insert(), and the mistakes that catch beginners out.
Appending is one of the first list operations every Python learner needs, because lists are rarely complete when you create them. You may start with an empty list and build it up from user input, from a file, from a loop, or from the results of a calculation. In each case, append() is the normal, readable way to grow the list one item at a time. If you are still setting up Python, first check which version you have installed by following our guide on how to check the Python version on Windows, Mac and Linux, because the behaviour described here works the same in Python 3, which is the version you should be using.
What Does Append Mean in Python?
In Python, to append means to add something to the end of an existing sequence. For lists, that is done with the append() method, which belongs to the list object itself. You call it with dot notation: my_list.append(item). The method changes the original list, which programmers call mutating it, rather than creating a new list. That is an important distinction. After you append, every other variable that points to the same list will see the new item too.
The word append is also used in a second, related sense in Python: opening a file in append mode, with open("file.txt", "a"), adds new text to the end of the file instead of overwriting it. The two ideas are the same in spirit — add to the end, keep what is already there — but the code is different. This guide covers list appending in detail first, then explains file appending near the end, so you do not mix the two up.
The append() Syntax
The syntax is deliberately simple:
list_name.append(item)
There is one argument, item, and it can be almost anything: a number, a string, a Boolean, another list, a dictionary, a tuple, or an object of your own class. The method takes no other arguments, it has no keyword form, and it always adds the item at the end, never at the start or in the middle. If you need a different position, use insert(), which is covered below.
A Basic Example
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)
# Output: ['apple', 'banana', 'cherry']
Notice that the print() call shows the changed list. You do not need to write fruits = fruits.append("cherry"). In fact, you must not do that, because append() returns None. Assigning its result back to the variable would replace your list with None, and that is one of the most common beginner errors in Python.
Appending to an Empty List
scores = []
scores.append(10)
scores.append(20)
scores.append(30)
print(scores)
# Output: [10, 20, 30]
Starting from an empty list is a very common pattern. You create the list before a loop, append inside the loop, and use the finished list afterwards. It is clear, it is easy to debug, and for most programs it is fast enough. Only when you are building very large lists in performance-critical code should you consider a list comprehension instead.
What Can You Append in Python?
Python lists are flexible: a single list can hold items of different types, and append() will accept any of them. You can append a string to a list of numbers, a number to a list of strings, or a whole list to another list. That flexibility is useful, but it is also a source of bugs, so think about what the list is supposed to contain before you append something different.
Appending a Single Value
Appending a single value is the normal case. The value is added as one element, and the length of the list grows by exactly one. Use len() before and after if you want to check this while you are learning.
numbers = [1, 2, 3]
numbers.append(4)
print(numbers) # [1, 2, 3, 4]
print(len(numbers)) # 4
Appending a List to a List
If you append a list, Python adds the whole list as a single nested element. It does not merge the two lists together. That is correct behaviour, but it surprises many beginners.
teams = ["Arsenal", "Chelsea"]
teams.append(["Liverpool", "City"])
print(teams)
# Output: ['Arsenal', 'Chelsea', ['Liverpool', 'City']]
print(len(teams)) # 3, not 4
If you wanted four separate team names, you should use extend() instead, which adds each item from the second list individually. The difference between append() and extend() is one of the first things to learn, and it is explained in the comparison table below.
Appending Other Types
You can append a dictionary, a tuple, or a set to a list, and each becomes one element. This is useful when a list represents a collection of records, for example a list of users where each user is a dictionary.
users = []
users.append({"name": "Aisha", "age": 28})
users.append({"name": "Ben", "age": 34})
print(users[0]["name"]) # Aisha
append() vs extend() vs insert() vs +=
Python gives you several ways to add items to a list, and choosing the wrong one is a common source of errors. The table below summarises the differences, then each method is explained in words.
| Method | What it does | Length grows by | Best for |
|---|---|---|---|
append(item) |
Adds one item to the end | 1 | Adding a single item |
extend(iterable) |
Adds each item from another iterable to the end | Length of the iterable | Merging two lists |
insert(index, item) |
Adds one item at a chosen position | 1 | Adding in the middle |
list += iterable |
Same as extend, using an operator | Length of the iterable | Short, readable merging |
list + other |
Creates a new combined list | Length of the other list | When you must not change the original |
When to Use extend()
Use extend() when you have another list, tuple, or set and you want all of its items to become separate elements of your list. For example, [1, 2].extend([3, 4]) gives [1, 2, 3, 4], while [1, 2].append([3, 4]) gives [1, 2, [3, 4]]. If your code keeps producing nested lists when you expected a flat list, you almost certainly need extend() instead of append().
When to Use insert()
Use insert() when the position matters. insert(0, "first") puts an item at the start, and insert(2, "third") puts it at index 2, pushing later items one place to the right. Inserting is slower than appending for long lists, because Python has to move the items after the insertion point, so do not use it in a tight loop when appending and sorting afterwards would do.
When to Use += or +
The += operator behaves like extend() for lists: it changes the list in place. The + operator is different: it creates a brand-new list and leaves both originals unchanged. That distinction matters when another variable shares the same list, or when you are passing a list into a function and do not want the function to change it.
How to Append in a Loop
Appending inside a loop is the classic use case. The pattern below collects only the even numbers from 1 to 10, and it shows the three parts clearly: create an empty list, loop, and append when a condition is met.
evens = []
for number in range(1, 11):
if number % 2 == 0:
evens.append(number)
print(evens) # [2, 4, 6, 8, 10]
You will see the same pattern when reading files, when collecting results from an API, and when processing user input. A list comprehension can do the same job in one line — evens = [n for n in range(1, 11) if n % 2 == 0] — and experienced Python programmers often prefer it, because it is shorter and faster. As a beginner, however, the explicit loop with append() is easier to read and easier to debug, so learn that first and move to comprehensions when you are comfortable.
Appending User Input
names = []
for _ in range(3):
name = input("Enter a name: ")
names.append(name)
print(names)
Always validate input before you append it in a real program. Check that a number really is a number, strip extra spaces from text with .strip(), and skip empty entries. Appending bad data and discovering it later is much harder than rejecting it at the point of entry.
Common Mistakes When You Append in Python
1. Assigning the Result of append()
As noted above, append() returns None. Writing my_list = my_list.append("x") destroys the list. Just call the method on its own line, and do not assign its result.
2. Appending a List When You Meant to Extend
If your list ends up looking like [1, 2, [3, 4]] when you expected [1, 2, 3, 4], you used append() where extend() was needed. Check the shape of your data with print() after the first append, and the problem becomes obvious.
3. Appending the Same Mutable Object Twice
Appending a list or dictionary adds a reference to that object, not a copy of it. If you append the same dictionary twice and then change it, both entries change, because they are the same object. Use .copy(), or create a new dictionary each time through the loop, to avoid this trap.
row = {"score": 0}
results = []
results.append(row.copy())
row["score"] = 10
results.append(row.copy())
print(results) # [{'score': 0}, {'score': 10}]
4. Forgetting That append() Only Works on Lists
Tuples and strings are immutable in Python, so they have no append() method. Trying "hello".append("!") or (1, 2).append(3) raises an AttributeError. For a tuple, convert it to a list first, append, and convert back if you need a tuple again. For a string, use concatenation or join a list of parts.
5. Appending Inside a Function Without Returning the List
Because append() changes the list in place, a function that appends to a list passed in as an argument will change the caller’s list too. That can be useful, but it can also be a surprise. Document the behaviour, or return the list explicitly so the caller can see what happened.
Append to a File in Python
Separately, Python lets you append text to a file by opening it in append mode, "a". New text is written at the end of the file, and existing content is kept. If the file does not exist, Python creates it.
with open("notes.txt", "a") as file:
file.write("Another line\n")
Use "a" when you want to add to a log or a notes file. Use "w" only when you want to overwrite the file completely, because write mode erases the old content first. The with statement closes the file for you, even if an error occurs, so always use it instead of opening and closing files by hand.
Performance and Best Practice
Appending to the end of a list is fast in Python. Lists are designed for it, and the operation is amortised constant time, which means the average cost stays roughly the same even as the list grows. Appending to the start, by contrast, is slow for long lists. If you find yourself inserting at position zero repeatedly, consider building the list in reverse and reversing it at the end, or use a collections.deque, which is designed for adding at both ends.
A few habits will keep your code clean. Give the list a plural name, such as users or scores, so the code reads naturally. Keep lists of one type of item where you can, so later code does not have to guess what each element is. Prefer append() for one item and extend() for many, and say so in a comment when the choice is not obvious. When you move on to larger projects, choosing a good editor will help too: our round-up of the best Python IDEs for beginners and pros compares seven tools, including free options, so you can pick one that fits how you work.
Frequently Asked Questions
How do I append in Python?
Use list.append(item). It adds one item to the end of the list and changes the list in place. For example, [1, 2].append(3) is not valid on its own as an expression you assign, but numbers = [1, 2]; numbers.append(3) gives [1, 2, 3].
What is the difference between append and extend in Python?
append() adds one item as a single element, so appending a list creates a nested list. extend() adds each item from an iterable as separate elements, so extending with a list merges the two lists into one flat list.
Does append() return a new list?
No. append() returns None and changes the original list in place. If you need a new list, use list + [item], which leaves the original unchanged.
Can I append multiple items at once?
Not with a single append() call, because it takes exactly one argument. To add several items at once, use extend() with a list of the items, or use +=, for example numbers.extend([4, 5, 6]).
How do I append to a file in Python?
Open the file in append mode with open("file.txt", "a") and write to it, ideally inside a with statement. New text is added at the end of the file, and existing text is preserved. Use "w" only if you want to overwrite the file.
To append in Python, remember the short version: list.append(item) adds one item to the end, changes the list in place, and returns None. Use extend() to merge lists, insert() to add at a position, and append mode "a" to add text to a file. With those four tools, you can build and grow lists and files confidently in almost any beginner or intermediate program.
[…] How to Append in Python: append() Explained With Examples […]