In this tutorial, we will learn how to create an empty list. In other words, a List with no elements But before that What’s A Python List Exactly?
In short, a list is a collection of arbitrary objects, somewhat akin to an array in many other programming languages but more flexible. Lists are defined in Python by enclosing a comma-separated sequence of objects in square brackets ([]
)
To create an empty list in python, assign the variable with empty square brackets.
mylist = []
You can also use list class constructor as shown below to create an empty list.
mylist = list()
Example 1: Create an Empty List
In the following example, we will create an empty list and check the datatype of the variable.
books = []
print(type(books))
Output: <class 'list'>
Example 2: Create an Empty List
In the following example, we will create an empty list using list class constructor.
books = list()
print(type(books))
Output: <class 'list'>