Skip to main content

How to Add an Item to the End of a List in Python with append

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A list often grows while a program runs: one more item in a basket, one more word in a sentence, one more result in a table. append adds one item to the end of a list, and the list keeps everything it already had. This guide does it on Python 3.15.2.

Syntax​

Syntax
<list>.append(<item>)
PartWhat it means
<list>The list to add to. append changes this list itself
.append(...)Adds one item after the last one
<item>The value to add: a string, a number or anything else

The Python tutorial describes list.append in one line: "Add an item to the end of the list."

The Example​

A shopping basket starts with milk and bread. The script adds eggs, then prints the basket and how many items it holds.

Prerequisites​

  • uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

basket.py
basket = ["milk", "bread"]

basket.append("eggs")

print(basket)
print(len(basket))

The basket.py script in a macOS-style code window: a basket list of milk and bread, basket.append("eggs"), then prints of the basket and its length.

The append line stands on its own. There's no basket = in front of it, because append changes the list that basket already names.

Step 2: Run It​

Terminal
uv run python basket.py
Output
['milk', 'bread', 'eggs']
3

The terminal after uv run python basket.py: the list milk, bread, eggs, then 3.

eggs is now the last item, after milk and bread, and the list holds three items instead of two. The command works unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Saving the result: basket = basket.append("eggs")append returns None, so basket became None and the list was lost. The next basket.append("jam") raised AttributeError: 'NoneType' object has no attribute 'append'Write basket.append("eggs") on a line of its own
Appending a list to add several itemsbasket.append(["tea", "jam"]) gave ['milk', 'bread', ['tea', 'jam']]: the whole list went in as one item, and len(basket) was 3Use extend: basket.extend(["tea", "jam"]) gave ['milk', 'bread', 'tea', 'jam']
Passing two itemsbasket.append("tea", "jam") raised TypeError: list.append() takes exactly one argument (2 given)Call append once per item, or use extend with a list

FAQ​

How do I add an item at the start instead?​

Use insert with the position 0. basket.insert(0, "apples") gave ['apples', 'milk', 'bread']. The tutorial says a.insert(0, x) "inserts at the front of the list".

Can I append to an empty list?​

Yes. Starting from basket = [], two calls of basket.append("milk") gave ['milk', 'milk']. That also shows a list can hold the same item twice.

How is append different from joining lists with +?​

basket + ["eggs"] builds a new list and leaves basket as it was: the new list was ['milk', 'bread', 'eggs'], and basket still held ['milk', 'bread']. append changes basket itself and builds nothing new.

Does append work on a tuple?​

No. A tuple can't be changed after it's made. With basket = ("milk", "bread"), the call basket.append("eggs") raised AttributeError: 'tuple' object has no attribute 'append'.

Conclusion​

basket.append("eggs") added eggs after the last item and changed basket itself, which then held ['milk', 'bread', 'eggs']. It returns None, so it belongs on a line of its own.

Additional Resources​