manyspikes

Sequences

So far, we have seen how we can define numbers, strings of text and True/False values with Python. However, often we are interested in looking at sequences of values rather than just one value.

For instance, you might be interested in analysing your savings over time, or perhaps look at your expenses over the past month.

To work with this type of data, we need basic data structures that can represent sequences. Python provides two main built-in types for this purpose: lists and tuples.

In the next sections, we will learn how to use lists and tuples to store sequences of values and perform basic operations on them.

But why do we need both tuples and lists? It turns out they are quite different under the hood, so we will take a look at the main differences between them.