In this post, we will see how to create an empty list in python.
There are two ways to create an empty list in Python.
- Using [ ]
- Using list() function.
Let’s see this with the help of example.
Which is faster: [ ] or list()
list() is inherently slower than , because of
- symbol lookup (no way for python to know in advance if you did not just redefine list to be something else!)
- function invocation
- then it has to check if there was iterable argument passed (so it can create list with elements from it)
That’s all about creating empty list in python.