How to Create an Empty List in Python?

To store multiple data types such as string, int, float, etc into a single variable, the list data structure is used in Python. Empty lists do not contain any items or elements. The empty list is used in the program to add or append other values into it using different functions such as append(), insert(), etc.

To create an empty list, the square brackets [ ] method and list() function are used in Python. This post will explain the multiples method to create an empty list in Python.

Method 1: Using Square Brackets [ ]

The easiest way to create/initialize the empty list in Python is using a square bracket. Let’s see the following examples to create single or nested empty lists:

Example 1: Create/Initialize an Empty List

The below code is used to create the empty list using the square bracket:

Code:

empty_list = []
print('Empty List: ',empty_list)
print('Length of List: ', len(empty_list))

The empty list or list without any element is initialized in the program. The “len()” function is utilized to retrieve the length of the empty list.

Output:

The empty list has been created.

Example 2: Create Empty List of Lists

The below code is utilized to initialize an empty list of lists in Python:

Code:

size = 5
empty_list = [[] for _ in range(size)]
print('Empty List: ',empty_list)
print('Length of List: ', len(empty_list))

The size of the empty list is assigned to a variable named “size”. In list comprehension, the for loop iterates over the specific range and creates an empty nested list.

Output:

The empty nested list of specific sizes has been created.

Example 3: Add Items or Elements to an Empty List

The below code is used to add items to an empty list:

Code:

empty_list = []
for items in range(5):
    empty_list.append(items)
print(empty_list)

An empty list is initialized to a variable “empty_list”. The for loop iterates over the range and the “append()” method adds the items to the empty list based on the specified range.

Output:

The items have been added to an empty list.

Method 2: Using list() Function

We can also create an empty list utilizing the “list()” function. Here is an example code:

Code:

empty_list = list()
print('Empty List: ',empty_list)
print('Length of List: ', len(empty_list))

The “list()” function is used without any argument and assigned to a variable named “empty_list”. The “len()” function takes an empty list as an argument and retrieves the length. 

Output:

The empty list has been created.

Conclusion

To create/initialize an empty list, the list() function and square brackets [ ] are used in Python. The nested empty list is created using the list comprehension method. The “len()” function is utilized to fetch the length of an empty list. We can append multiple items to an empty list utilizing the “append()” function. This tutorial explained various ways to create/initialize an empty list in Python.