2

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 = [] ?

1 Answers1

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