Dr. Cho’s Website
Course Materials

Sequence data types in Python

Dr. Huidae Cho
Institute for Environmental and Spatial Analysis...University of North Georgia

1   Tuples

Tuples are array-like immutable objects.

Immutable objects cannot be modified once defined.

Elements are accessed using a 0-based index.

x = (1, 2.3, '4', [10, 20]) # create a tuple with different data types
len(x)                      # tuple size
x[0]                        # first element
x[0] = 10                   # try to modify it
x[3][0]                     # 2-dimensional indexing
x[3][0] = 1                 # works?

2   Lists

Lists are array-like mutable objects.

Mutable objects can be modified.

Elements are accessed using a 0-based index.

x = [1, 2.3, '4', (10, 20)] # create a list with different data types
len(x)                      # list size
x[0]                        # first element
x[0] = 10                   # try to modify it
x[3][0]                     # 2-dimensional indexing
x[3][0] = 1                 # works?

3   Slicing array-like objects

Slicing array-like objects is not any different from slicing strings.

Use the same slicing method to access individual elements in an array-like object.