Python – Create an Empty List
Python list is a data structure that can store multiple elements of heterogeneous type. At some point in your program, you may need to create an empty list and add items to it in the subsequent steps.
In this tutorial, we shall learn how to create an empty list. In other words, a List with no elements.
To create an empty list in python, assign the variable with empty square brackets.
mylist = []
Run []
is an empty list.
You can also use list class constructor as shown below to create an empty list.
mylist = list()
Run Example 1: Create an Empty List
In the following example, we will create an empty list and check the datatype of the variable.
Python Program
cars = []
print(type(cars))
Run Output
<class 'list'>
If you check the length of this Python list, you would get zero as length.
Example 2: Create an Empty List
In the following example, we will create an empty list using list class constructor.
Python Program
cars = list()
print(type(cars))
Run Output
<class 'list'>
Summary
In this tutorial of Python Examples, we learned some of the ways to create an empty list, with the help of well detailed example programs.
Related Tutorials
- How to Append List to Another List in Python? – list.extend(list)
- How to Get List of all Files in Directory and Sub-directories?
- Python List of Functions
- Python – Convert List to Dictionary
- Python List – Add Item
- Python Program to Find Smallest Number in List
- Python List of Lists
- How to Check if Python List is Empty?
- How to Insert Item at Specific Index in Python List?
- Python – Count the items with a specific value in the List