Sequences

Carson West

Iterables

Sequences in Python

Sequences are a fundamental data structure in Python. They are ordered collections of items, meaning that the order in which items are added matters, and each item has a specific index. Several built-in types in Python are sequences.

Key characteristics:

Common Sequence Types:

my_list = 1, 2, 3
my_list.append(4)  # Add an item
my_list[0]] = 10   # Change an item
my_tuple = (1, 2, 3)
# my_tuple.append(4)  # This would raise an error because tuples are immutable
my_string = "Python"
my_string[0]]  # Accesses 'P'
for i in range(5):
    print(i) # prints 0, 1, 2, 3, 4

Sequence Operations:

Many operations work consistently across different sequence types:

Further Notes: