The list() function is a built-in function in Python that creates a list object from a given iterable. For example:
1 2 3 |
>>> my_list = list('abc') >>> my_list ['a', 'b', 'c'] |
You can also use it to create an empty list by calling list() with no arguments:
1 2 3 |
>>> empty_list = list() >>> empty_list [] |
You can also use it to create a list from a tuple or another list:
1 2 3 4 5 6 7 8 9 |
>>> my_tuple = ('a', 'b', 'c') >>> my_list = list(my_tuple) >>> my_list ['a', 'b', 'c'] >>> my_other_list = ['a', 'b', 'c'] >>> my_list = list(my_other_list) >>> my_list ['a', 'b', 'c'] |
list() is a powerful function that allows you to create lists from a variety of different iterable objects, making it a useful tool to have in your Python toolkit.
Younes Derfoufi
CRMEF OUJDA
1 thought on “The Python list() function”