What's the difference between creating a list with "list()" and "[]" in Python?

Viewed 47

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 Answers

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)
Related