How to Create an Empty List in Python? Examples


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 = []

[] is an empty list.

You can also use list class constructor as shown below to create an empty list.

mylist = list()

Examples

1. Create an empty list using square brackets

We can use square bracket representation to create an empty list. The expression containing left-square-bracket [ followed by right-square-bracket ] represents an empty array.

In the following program, we will create an empty list and check the datatype of the variable.

Python Program

myList = []
print('The list :', myList)
print('List length :', len(myList))

Output

The list : []
List length : 0

Since the list is empty, the length of myList is zero.

2. Create an empty list using list()

Python has list() built-in function that can be used to create an empty list.

In the following example, we will create an empty list using the list() built-in function.

The print out the list and list length to confirm the empty array.

Python Program

myList = list()
print('The list :', myList)
print('List length :', len(myList))

Output

The list : []
List length : 0

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.