Declare an empty List in Python
Lists are just like the arrays, declared in other languages. Lists need not be homogeneous always which makes it the most powerful tool in Python. A single list may contain DataTypes like Integers, Strings, as well as Objects. Lists are mutable, and hence, they can be altered even after their creation.
However, Have you ever wondered about how to declare an empty list in Python? This can be achieved by two ways i.e. either by using square brackets[] or using the list() constructor.
Using square brackets []
Lists in Python can be created by just placing the sequence inside the square brackets[]. To declare an empty list just assign a variable with square brackets.
Example:
# Python program to declare # empty list # list is declared a = [] print("Values of a:", a) print("Type of a:", type(a)) print("Size of a:", len(a)) |
Output:
Values of a: [] Type of a: <class 'list'> Size of a: 0
Using list() constructor
The list() constructor is used to create list in Python.
Syntax: list([iterable])
Parameters:
iterable: This is an optional argument that can be a sequence(string, tuple) or collection(dictionary, set) or an iterator object.Return Type:
- Returns an empty list if no parameters are passed.
- If a parameter is passed then it returns a list of elements in the iterable.
Example:
# Python program to create # empty list # list is declared a = list() print("Values of a:", a) print("Type of a:", type(a)) print("Size of a:", len(a)) |
Output:
Values of a: [] Type of a: <class 'list'> Size of a: 0
Recommended Posts:
- Python - Remove empty List from List
- Python: Get List of all empty Directories
- Python | Check whether a list is empty or not
- Python | First Non-Empty String in list
- Python | Initialize list with empty dictionaries
- Python | Check if any String is empty in list
- Python | Remove and print every third from list until it becomes empty
- Python | Splitting list on empty string
- Python | Remove empty tuples from a list
- Python | Remove trailing empty elements from given list
- Python - Ways to remove multiple empty spaces from string List
- Python | Remove empty strings from list of strings
- numpy.empty() in Python
- Python | Pandas DataFrame.empty
- Python Pytorch empty() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

