In [1]:
# lists are mutable sequences notated as []
[1, 2, 3]


Out[1]:
[1, 2, 3]

In [3]:
# like tuples, lists can contain any kind of object
t = [-12, 'fish', True]
t[0]


Out[3]:
-12

In [4]:
# indexing supports assignment
t[1] = 'clam'
t


Out[4]:
[-12, 'clam', True]

In [13]:
# append and binary operators grow lists
a = []
a.append(3)
a


Out[13]:
[3]

In [14]:
a.append(7)
a


Out[14]:
[3, 7]

In [15]:
a.append([5, 6, 7])
a


Out[15]:
[3, 7, [5, 6, 7]]

In [5]:
# lists support "in" to test for membership
5 in [5, 6, 7]


Out[5]:
True

In [6]:
# lists support equality tests
a = [5, 6, 7]
a == [5, 6, 7]


Out[6]:
True

In [7]:
# slicing access parts of lists
a = range(7)
a[2:5]


Out[7]:
[2, 3, 4]

In [8]:
# slicing supports assignment
x = 1
y = 2
a[x:y] = ['a','b','c']
a


Out[8]:
[0, 'a', 'b', 'c', 2, 3, 4, 5, 6]

In [9]:
a = list('fish')
a[1:3] = 'xx'
a


Out[9]:
['f', 'x', 'x', 'h']