December 2021
Intermediate to advanced
352 pages
10h
English
Python has a number of different collection objects: lists (essentially arrays), tuples, dictionaries, and sets. We look at all of them in this chapter, along with how we can read data into them from files.
We have already seen some simple examples of using Lists, the Python equivalent of arrays. You can create lists programmatically by simply declaring the contents inside square brackets.
nlist = [2, 4, 8, 16] # create list
Then you can access elements of the list by position: All lists start at index zero.
print (nlist[0]) # first element 2
You can access the final element by using an index of -1.
print (nlist[-1]) # last ...
Read now
Unlock full access