How to Add Elements to an Empty List in Python

If you need to add elements to an empty list in Python, call cart.append(item) to add one element, or cart.extend([...]) to add several at once. Both change the list in place.

Where people get stuck is the small stuff: append() with a list nests it, and assigning the result of append() gives you None.

In this article, I’ll show you the four ways I add elements to an empty list, plus the traps. I ran every snippet on Python 3.12.5.

The empty list we’ll fill

I’ll use a shopping cart for an online desk-setup store. It starts as cart = [], the empty-brackets form from creating an empty list in Python, and the items are:

  • Standing desk
  • Monitor arm
  • USB-C hub

Method 1: Add elements to an empty list in a for loop with append() (Recommended)

append() adds exactly one element to the end of the list.

cart = []
for item in ["Standing desk", "Monitor arm", "USB-C hub"]:
    cart.append(item)
print(cart, len(cart))

Output:

['Standing desk', 'Monitor arm', 'USB-C hub'] 3
Command Prompt output of Python append() in a for loop filling an empty shopping cart list with three items
The loop appends each item in turn, and the cart ends up as a three-item list in the same order.

How does this code work?

The cart starts empty, so its length is 0. Each pass through the loop calls append() with the next item.

For more on looping, see looping through a list in Python.

Method 2: Add several elements with extend()

When you already have a batch of items, extend() adds each one separately. For more on this, see extend vs append in Python.

cart = []
cart.extend(["Standing desk", "Monitor arm"])
print(cart)

wrong = []
wrong.append(["Standing desk", "Monitor arm"])
print(wrong, len(wrong))

Output:

['Standing desk', 'Monitor arm']
[['Standing desk', 'Monitor arm']] 1
Command Prompt output of Python extend() adding two items to an empty list while append() nests them as one element
extend() adds two separate items, while append() with a list leaves a single nested element.

How does this code work?

extend() loops over the list you give it and adds every item. So the cart gets two separate strings.

append() treats the whole list as one object, which is why the second list has a length of 1. To add many values quickly, appending multiple items to a list covers more patterns.

Method 3: Add an element at a position with insert()

insert(index, item) puts an element at a specific position. On an empty list, only one position really exists.

cart = []
cart.insert(0, "USB-C hub")
cart.insert(0, "Monitor arm")
cart.insert(5, "Standing desk")
print(cart)

Output:

['Monitor arm', 'USB-C hub', 'Standing desk']
Command Prompt output of Python insert() adding items to an empty list, where an out-of-range index still adds at the end
Each insert at index 0 goes to the front, and the index-5 insert on a short list lands at the end.

How does this code work?

Index 5 doesn’t exist yet, so Python doesn’t raise an error; it just adds the standing desk at the end. For front-of-list work, see adding an element to the beginning of a list.

Method 4: Add elements in a for loop with a condition or range()

The same append() loop can filter values or build them from range(). A comprehension does the second job in one line.

prices = [120.00, 80.00, 200.00, 50.00, 300.00]

premium = []
for price in prices:
    if price > 100:
        premium.append(price)
print(premium)

squares = []
for n in range(1, 6):
    squares.append(n * n)
print(squares)

print([n * n for n in range(1, 6)])

Output:

[120.0, 200.0, 300.0]
[1, 4, 9, 16, 25]
[1, 4, 9, 16, 25]
Command Prompt output of a Python for loop appending only prices above 100 and appending squares from range() to empty lists
The first list keeps only the prices above 100, and both square lists hold the same five numbers.

How does this code work?

The if test decides which prices get appended. range(1, 6) yields 1 to 5, and the comprehension is the shorter form of the same loop.

Why does my list turn into None after append()?

This one catches almost everyone once. append() changes the list and returns None, so assigning its result throws your list away.

cart = []
cart = cart.append("Standing desk")
print(cart)

try:
    cart.append("Monitor arm")
except AttributeError as err:
    print("AttributeError:", err)

Output:

None
AttributeError: 'NoneType' object has no attribute 'append'
Command Prompt output showing a Python list becoming None after assigning the result of append(), then an AttributeError
The cart prints None after the assignment, and the next append() fails with an AttributeError.

Just call cart.append(item) on its own line.

Things to Keep in Mind When Adding Elements

  • append() adds one object. Pass it a list and you get a nested list; use extend() instead.
  • Don’t assign the result of append(). It returns None; call it on its own line.
  • To avoid repeats, see removing duplicates from a list.

A few more list guides worth reading next:

Frequently asked questions

How do I add elements to an empty list in Python?

Create it with [], then call append() for one item or extend() for several.

What is the difference between append() and extend()?

append() adds its argument as one element. extend() adds each item of an iterable separately.

Why does my list become None after append()?

append() returns None. Don’t assign it back; just call it on the list.

Can I use insert() on an empty list?

Yes. Any index works; on an empty list the item simply becomes the first element.

Where are list methods documented?

See More on Lists in the Python docs.