Table of Contents
Lists are very useful in Python because they allow us to store multiple values inside a single variable.
Because of this, creating a list is one of the first things you will learn when you start learning Python.
In this article, we will learn the best ways to create an empty list in Python.
Using square brackets
The easiest and cleanest way to create an empty list in Python is to use square brackets.
This will create a list without any elements in then, thus making the length of the list 0.
PYTHONitems = []
length = len(items)
print(length)
BASH0
Now that you have a list, you can now proceed to add elements to it.
Here's an example of how to do that:
PYTHONitems = []
items.append(1)
items.append(2)
items.append(3)
length = len(items)
print(length)
print(items)
BASH3
[1, 2, 3]
Using the list constructor
Another way to create an empty list in Python is to use the list constructor.
This is a built-in function that allows you to create a list and by default it will be empty.
PYTHONitems = list()
length = len(items)
print(length)
BASH0
Just like before you can now add elements to the list.
PYTHONitems = list()
items.append(1)
items.append(2)
items.append(3)
length = len(items)
print(length)
print(items)
BASH3
[1, 2, 3]
Conclusion
In this article, we learned how to create an empty list in Python.
You can either use square brackets or the list constructor to create an empty list.
Thanks for reading!
 Getting Started with Solid Getting Started with Solid
 Git Tutorial: Learn how to use Version Control Git Tutorial: Learn how to use Version Control
 How to Serve Static Files with Nginx and Docker How to Serve Static Files with Nginx and Docker
 How to deploy a .NET app using Docker How to deploy a .NET app using Docker
 How to deploy a PHP app using Docker How to deploy a PHP app using Docker
 Using Puppeteer and Jest for End-to-End Testing Using Puppeteer and Jest for End-to-End Testing
 How to Scrape the Web using Node.js and Puppeteer How to Scrape the Web using Node.js and Puppeteer
 Build a Real-Time Chat App with Node, Express, and Socket.io Build a Real-Time Chat App with Node, Express, and Socket.io
 Learn how to build a Slack Bot using Node.js Learn how to build a Slack Bot using Node.js
 Creating a Twitter bot with Node.js Creating a Twitter bot with Node.js
 Using Push.js to Display Web Browser Notifications Using Push.js to Display Web Browser Notifications
 Getting Started with Vuex: Managing State in Vue Getting Started with Vuex: Managing State in Vue
