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
Acheter sur Très Facile !
-
Langage Python pour les Nuls, 3e éd - John Paul Mueller
€ 24,00 Acheter le livre -
Tenda Routeur WiFi 6 RX12 Pro, Router Tenda WiFi AX3000 Bi-Bande, 5 * 6dBi Antennes à Haut Puissance, Large Couverture,
€ 57,00 Acheter le livre -
Python pour les Nuls, 4è édition - John Paul Mueller
€ 25,00 Acheter le livre
1 thought on “The Python list() function”