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
- Python – Check if List Contains all Elements of Another List
- Python List without Last Element
- Python – List of Strings
- How to Insert Item at Specific Index in Python List?
- How to Append List to Another List in Python? – list.extend(list)
- Python – Traverse List except Last Element
- How to Reverse Python List?
- Python Program to Find Smallest Number in List
- How to Get the list of all Python keywords?
- Python – Count the items with a specific value in the List