Create an empty list

 

What You'll Learn: In this tutorial, you'll discover how to create an empty list in Python. A list is like a container that can store multiple items of different types.

What is an Empty List?

An empty list is simply a list with no elements. You can think of it as an empty basket ready to be filled with items later.

Creating an Empty List

There are two common ways to create an empty list in Python:

  1. Using Square Brackets

    • You can create an empty list by assigning a variable with empty square brackets [].

    Example Code:

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

    Output: 

    The list: []
    List length: 0
    

    This code creates an empty list and checks its length, which is zero since it's empty.

  2. Using the list() Function

    • You can also use the list() built-in function to create an empty list.

    Example Code:

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

    Output:

    The list: []
    List length: 0
    

    This method also creates an empty list and confirms its length is zero.

Summary:

In this Python tutorial, we learned how to create an empty list using two methods: square brackets [] and the list() function. An empty list is useful when you want to start with an empty container and add items to it later. Keep experimenting and have fun with lists in Python!