What is the best way to create a new empty list in Python?
l = []
or
l = list()
I am asking this because of two reasons:
- Technical reasons, as to which is faster. (creating a class causes overhead?)
- Code readability – which one is the standard convention.
Here is how you can test which piece of code is faster:
However, in practice, this initialization is most likely an extremely small part of your program, so worrying about this is probably wrong-headed.
Readability is very subjective. I prefer
[], but some very knowledgable people, like Alex Martelli, preferlist()because it is pronounceable.