First page Back Continue Last page Overview Graphics

Appending Elements to a List

An element can be appended to a list L with the “+” operator:

L = L + [item]

Example:

>>> L = [3,4]

>>> L = L + [42]

>>> L

[3, 4, 42]

or

>>> L = [3,4]

>>> L += [42]

>>> L

[3, 4, 42]

Using append :

L.append(item)

Example:

>>> L = [3,4]

>>> L.append(42)

>>> L

[3, 4, 42]

Augmented Assignment