I've always used
new_list = list()
to create a list in Python 3 because I think it's more elegant, but is it any different than
new_list = []
?
Asked
Active
Viewed 50 times
2

William Vernaschi
- 37
- 6
-
1https://stackoverflow.com/questions/33716401/whats-the-difference-between-list-and – Ευάγγελος Γρηγορόπουλος Mar 24 '20 at 23:14
1 Answers
1
list()
will create []
so in the end, the result it is not different
from performance perspective []
is faster
%timeit list()
# 99.6 ns ± 0.871 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
%timeit []
# 36 ns ± 15.2 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

kederrac
- 16,819
- 6
- 32
- 55
-
A theory on why the performance difference exists: ‘list’ needs to be looked up at runtime (it can be redefined) [] cannot. Also points out potential difference. – Dave Mar 25 '20 at 00:11