Python – How to Create an Empty List?

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.