Adding Elements
We have two functions available for
adding new elements to a list, and these are:
1. The
append(value) method adds a new element
at the end of the list, with the value sent as an argument:
Obviously, the length of the list increases by one each time.
2. The
insert(index, value) method is superior to the previous one because it adds a new element
at the desired position in
the list, shifting all existing elements to the right by one:
Thus, we can insert a new element at the desired position in the list.
EXAMPLE
Interesting, right?
More would mean
a chapter of a book. Python is
object-oriented, and the values we refer to that can be introduced as list
elements are actually
objects. So, an element of a list can be ... another list! Look at this small
example: