Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

What is the best way to create a new empty list in Python?

l = []


l = list()

I am asking this because of two reasons:

  1. Technical reasons, as to which is faster. (creating a class causes overhead?)

  2. Code readability - which one is the standard convention.

1 Answer

0 votes
by (106k points)
edited by

For creating an empty list in Python you can use the below-mentioned piece of code which is faster:-

% python -mtimeit "l=[]" 

10000000 loops, best of 3: 0.0711 usec per loop 

% python -mtimeit "l=list()" 

1000000 loops, best of 3: 0.297 usec per loop

For the readability shake, you should prefer [].

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
asked Jul 15, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked May 30, 2019 in Python by Anvi (10.2k points)

Browse Categories