![]() |
VOOZH | about |
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.
[] <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.
As discussed above, we can create an empty list or convert any iterable to list using list() constructor. Let's see some more examples.
[0, 1, 2] [0, 1, 4, 9, 16]
Creating Nested List with list() constructor
Shallow copy of List using list()