Sequences

What is a sequence?

A sequence is a data structure which stores an items collection in a particular order. In some languages, a sequence can only contain one type of items; in other languages, including Python, a sequence can have different types of items.

Why are sequences important?

Sequences are important when you need to store items in a particular order. For example, a list of website users might be ordered according to when each user signed up.

What kinds of things can you do with a sequence?

With a sequence, you can add or remove items, work with individual or groups of items, determine whether a value is in the sequence, look for unique or duplicate items, loop through the sequence and do something with each item, and work with items that math particular conditions.

What kind of sequences are available in Python?

In Python, the main sequence type is the list, which are mutable. There are also tuples, which are immutable sequences, meaning that they can't be changed after being defined. Strings are a special type of sequence, as each element is a character in the sequence.

What is a mutable sequence?

A mutable sequence is a sequence that can be modified after creating them.