The short answer
Both [] and list() create a new, empty list. They differ in how they get there. [] is a list literal, which Python builds directly. list() calls the built-in list type to make one.
a = []
b = list()
print(a == b, type(a) is type(b)) # True True
Both results are mutable, so you can append to either one.
Converting other values
list() takes any iterable and builds a list from its items. [] takes the items you write between the brackets and does not convert anything.
list("abc") # ['a', 'b', 'c']
list(range(3)) # [0, 1, 2]
["abc"] # ['abc'], one string as one item
Use list(...) to convert something that is not a list yet, such as a string, a range or a tuple. Methods like split() return lists as well, which is covered in how to split a string with a delimiter in python.
Speed
[] is usually a little faster. Python can build the empty list in one step, while list() first looks up the name list and then calls it. The difference is small and rarely matters, but you can test it on your own machine with timeit:
import timeit
print(timeit.timeit("[]", number=1_000_000))
print(timeit.timeit("list()", number=1_000_000))
Shadowing the name list
Your own code can rebind the name list. After that, list() may stop working, but [] still works.
list = [1, 2, 3]
list() # TypeError: 'list' object is not callable
Avoid naming a variable list, which is a common source of this error.
Comparing with C++
Python’s list is a dynamic array, so the closest C++ type is std::vector, not std::list. C++ has no bracket literal for vectors, but braces do similar work:
#include <vector>
std::vector<int> a; // empty, like []
std::vector<int> b{1, 2, 3}; // like [1, 2, 3]
std::vector<int> c(3, 0); // three zeros, like [0] * 3
std::vector<int> d{3}; // one element, the value 3
The last two lines show a pitfall. Parentheses and braces mean different things, so c(3, 0) builds three zeros, while d{3} builds a vector holding the single value 3. For all the ways to fill a vector, see c vector initialization.
Summary
- Use
[]for a new empty list, or to write out the items. - Use
list(...)to convert another iterable. - Both give an equal, mutable list, and
[]is usually a little faster.
A similar trap shows up with sets, where the answer is different: Is set() the same as {}? No, because {} is an empty dict.