Declare an Empty List in Python (original) (raw)
Last Updated : 01 May, 2025
Declaring an empty list in Python creates a list with no elements, ready to store data dynamically. We can initialize it using [] or list() and later add elements as needed.
Using Square Brackets []
We can create an empty list in Python by just placing the sequence inside the square brackets[]. To declare an empty list just assign a variable with square brackets.
Python `
a = []
print(a)
print(type(a)) print(len(a))
`
Output
[] <class 'list'> 0
**Explanation:
- **a = []: Initializes an empty list and assigns it to variable a.
- **print(a): Prints the empty list [].
- **print(type(a)): Prints the type of a, which is <class ‘list’>, confirming that a is a list.
- **print(len(a)): Prints the length of a, which is 0, since the list is empty.
Using the list() Constructor
list() constructor is used to create a list in Python. It returns an empty list if no parameters are passed.
Python `
a = list()
print(a)
print(type(a)) print(len(a))
`
Output
[] <class 'list'> 0
**Explanation:
- **a = list(): Initializes an empty list using the list() constructor and assigns it to variable a.
- **print(a): Prints the empty list [].
- **print(type(a)): Prints the type of a, which is <class ‘list’>, confirming that a is a list.
- **print(len(a)): Prints the length of a, which is 0, since the list is empty.
**Related Articles:
Similar Reads
- Initialize an Empty Dictionary in Python To initialize an empty dictionary in Python, we need to create a data structure that allows us to store key-value pairs. Different ways to create an Empty Dictionary are: Use of { } symbolUse of dict() built-in functionInitialize a dictionaryUse of { } symbolWe can create an empty dictionary object 3 min read
- Check if a list is empty or not in Python In article we will explore the different ways to check if a list is empty with simple examples. The simplest way to check if a list is empty is by using Python's not operator. Using not operatorThe not operator is the simplest way to see if a list is empty. It returns True if the list is empty and F 2 min read
- Create an empty file using Python File handling is a very important concept for any programmer. It can be used for creating, deleting, and moving files, or to store application data, user configurations, videos, images, etc. Python too supports file handling and allows users to handle files i.e., to read and write files, along with 3 min read
- Declaring an Array in Python An array is a container used to store the same type of elements such as integer, float, and character type. An Array is one of the most important parts of data structures. In arrays, elements are stored in a contiguous location in a memory. We can access the array elements by indexing from 0 to (siz 4 min read
- Listing out directories and files in Python The following is a list of some of the important methods/functions in Python with descriptions that you should know to understand this article. len() - It is used to count number of elements(items/characters) of iterables like list, tuple, string, dictionary etc. str() - It is used to transform data 6 min read
- Python | Pandas DataFrame.empty Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure o 2 min read
- Cloning or Copying a List - Python In Python, lists are mutable, meaning they can be modified after creation. Often, we may need to create a copy of a list to preserve the original data while making changes to the duplicate. Cloning or copying a list can be done in multiple ways, each with its own characteristics. Let's discuss vario 3 min read
- Extending a list in Python In Python, a list is one of the most widely used data structures for storing multiple items in a single variable. Often, we need to extend a list by adding one or more elements, either from another list or other iterable objects. Python provides several ways to achieve this. In this article, we will 2 min read
- Python - API.create_list() in Tweepy Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from 2 min read
- How to check if a deque is empty in Python? In this article, we are going to know how to check if a deque is empty in Python or not. Python collection module provides various types of data structures in Python which include the deque data structure which we used in this article. This data structure can be used as a queue and stack both becaus 3 min read