December 2017
Beginner to intermediate
410 pages
12h 45m
English
Lists are a fundamental data structure in Python. They are used to store heterogeneous data, and are created with a pair of square brackets, [].
my_list = ['a', 1, True, 3.14]
We can subset the list using square brackets and provide the index of the item we want.
# get the first item print(my_list[0])
We can also pass in a range of values (Appendix L).
# get the first 3 values print(my_list[:3])
We can reassign values when we subset values from the list.
# reassign the first value
my_list[0] = 'zzzzz'
print(my_list)
Lists are objects in Python (Appendix S), so they will have methods that they can perform. For example, we can append values to the list.