Creating an empty list in Python
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Creating an empty list looks trivial in Python, but it shows up everywhere: collecting results, building a queue, accumulating errors, or preparing a mutable value for later use. Because lists are mutable, the way you create and reuse them has real consequences for correctness.
In practice, there are two standard ways to make an empty list: [] and list(). Both work, but [] is the normal choice because it is shorter and slightly more direct.
The Two Standard Ways
The most common pattern is the literal syntax:
You can also use the constructor:
These produce the same result: a new empty list object. For most code, prefer [] because it is easier to read and is the idiomatic Python style.
Why an Empty List Is Useful
An empty list is often the starting point for incremental work. You create it once, then append values as they become available.
This prints:
That pattern is common when the final size is not known in advance. It is also useful when filtering data:
In many cases, a list comprehension is even cleaner, but understanding the empty-list pattern is still important because it makes list mutation explicit.
Empty Lists in Functions
A very common use case is collecting values inside a function and returning them to the caller.
The empty list belongs inside the function because each call should get a fresh container. This matters a lot when writing helper functions or APIs.
If you use type hints, the intent becomes even clearer:
Avoid Reusing the Same Mutable List by Accident
The real mistakes usually happen after the list is created. Assigning the same list to another variable does not copy it. Both names point to the same underlying object.
Both variables show the same content because there is only one list in memory. If you need a separate list, create a new one or make an explicit copy.
The Mutable Default Argument Trap
This is the most important pitfall related to empty lists. Do not use [] as a function default unless you want the same list to be shared across calls.
Bad example:
That default list is created once, not once per call. The result is surprising:
The second call returns a list that already contains "x".
The correct version is:
Now each call gets a fresh list unless the caller intentionally provides one.
Common Pitfalls
- Using
listas a variable name shadows the built-inlist()constructor. - Assuming assignment copies a list. It only creates another reference.
- Using
[]as a default function argument can leak values across calls. - Building a list in a loop is fine, but for simple transformations a list comprehension is often shorter and clearer.
- Reusing a list between unrelated operations can produce hidden state bugs. Create a fresh empty list when you need a fresh result.
Summary
- '
[]andlist()both create a new empty list.' - '
[]is the normal, idiomatic form in Python code.' - Empty lists are useful for collecting values incrementally with
append. - Create the list inside a function when each call needs independent state.
- Be careful with aliasing and mutable default arguments because they create subtle bugs.

