Contents
- Introduction
- Example 1: Create an Empty List
- Example 2: Create an Empty List
- Summary
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[]RunExample 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]]RunOutput
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]]RunOutput
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.
Related Tutorials
- Python List with First N Elements
- Python List Add Item
- Python Count the items with a specific value in the List
- Python Check if List Contains all Elements of Another List
- How to Get List of all Files in Directory and Sub-directories?
- Python Convert List to Dictionary
- Python List of Strings
- Python List of Dictionaries
- How to Append List to Another List in Python? list.extend[list]
- Python Program to Find Largest Number in a List