list() constructor in Python Last Updated : 07 Nov, 2024 Comments Improve Suggest changes Like Article Like Report In Python list() constructor is a built-in function which construct a list object. We can use list constructor to create an empty list or convert an iterable (dictionary, tuple, string etc.) to a list. Python # Example of list constructor a = list() # creates an empty list b = list((1, 2, 3)) # covert tuple into list c = list("GfG") # covert string into list print(a, type(a)) print(b, type(a)) print(c, type(a)) Output[] <class 'list'> [1, 2, 3] <class 'list'> ['G', 'f', 'G'] <class 'list'> Syntax of list()list([iterable])We can pass optional argument to list() as iterable. If no iterable is provided, it returns an empty list. Use of list() constructor As discussed above, we can create an empty list or convert any iterable to list using list() constructor. Let's see some more examples. Python # range() function returns a range object. # list() can convert this object to a list a = list(range(3)) print(a) # Convert a comprehension to list b = list(x * x for x in range(5)) print(b) Output[0, 1, 2] [0, 1, 4, 9, 16] Creating Nested List with list() constructor Python mat = list([list(range(3)) for _ in range(3)]) print(mat) # output: [[0, 1, 2], [0, 1, 2], [0, 1, 2]] Shallow copy of List using list() Python a = [1, 2, 3] a1 = list(a) a1[0] = 5 print(a) # Output: [1, 2, 3] # different case for Nested List b = [[1, 2, 3], [4, 5, 6]] b1 = list(b) # changing b1 will also reflect in b b1[0][0] = 10 print(b) # Output: [[10, 2, 3], [4, 5, 6]] Comment More infoAdvertise with us Next Article list() constructor in Python abhishek1 Follow Improve Article Tags : Python python-list Practice Tags : pythonpython-list Similar Reads Constructors in Python In Python, a constructor is a special method that is called automatically when an object is created from a class. Its main role is to initialize the object by setting up its attributes or state. The method __new__ is the constructor that creates a new instance of the class while __init__ is the init 3 min read dict() Constructor in Python In Python, the dict() constructor is used to create a dictionary object. A dictionary is a built-in data type that stores data in key-value pairs, similar to a real-life dictionary where each word (the key) has a meaning (the value). The dict() constructor helps you create empty dictionaries or conv 2 min read set() Constructor in Python In Python, the set() constructor is used to create a set object. A set is a built-in data type that stores an unordered collection of unique elements. The set() constructor can be used to create an empty set or convert other data types (like lists, tuples, or strings) into a set.Example:Python# Exam 2 min read Convert Tuple to List in Python In Python, tuples and lists are commonly used data structures, but they have different properties:Tuples are immutable: their elements cannot be changed after creation.Lists are mutable: they support adding, removing, or changing elements.Sometimes, you may need to convert a tuple to a list for furt 2 min read Method And Constructor Overloading In Python In object-oriented programming, method, and constructor overloading are powerful features that allow developers to define multiple methods or constructors with the same name but with different parameters. This flexibility enhances code readability, and reusability, and provides a more intuitive inte 4 min read Convert Generator Object To List in Python Python, known for its simplicity and versatility, provides developers with a plethora of tools to enhance their coding experience. One such feature is the generator object, which allows for efficient iteration over large datasets without loading them entirely into memory. In this article, we'll expl 3 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 __init__ in Python Prerequisites - Python Class and Objects, Self__init__ method in Python is used to initialize objects of a class. It is also called a constructor. It is like a default constructor in C++ and Java. Constructors are used to initialize the objectâs state.The task of constructors is to initialize (assig 5 min read Python Linked List In this article, we will learn about the implementation of a linked list in Python. To implement the linked list in Python, we will use classes in Python. Now, we know that a linked list consists of nodes and nodes have two elements i.e. data and a reference to another node. Let's implement the node 13 min read Declare an Empty List in Python 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 dec 3 min read Like