Lists

Lists are ordered sequences that can store different object types. Lists are identified by [] brackets. We have previously seen indexing and slicing, and these techniques work the same with lists.

You should be able to understand the code below, based on previous exercises. In this case, len returns the numbers of elements in the list, not the number of characters (for example, the number 10.13 would be a single element).

You can also concatenate lists.

Lists can also be nested; you can have lists of lists.

In previous notes I explained the term immutable. I demonstrated that strings are immutable. However, lists are mutable, individual items may be indexed and selectively edited.

Lists have a range of available methods, we can edit the list in place, appending items.

It can be very useful to take a string of data and create a list based on the contents of that string. For example, a comma/space delimited file (CSV) if a very normal way to exchange data. You can then iterate over the individual items; we will cover that in a later walkthrough.

Finally

Review the methods documented here

Experiment with some of these methods to see how they work.

Last updated