More on Lists and Strings
Python allows slicing to select parts of a sequence type such as a list or a string.
Slicing uses a bracket cum colon notation to define slices. At its most simple,
sequence[a:b]
are all elements starting with index a and stoping before
index b. Negative numbers mean counting from the end. A missing number is
replaced by a default value, namely the first or the last element of the sequence.
Thus alist[:-1]
means all elements in alist
with the exception
of the last one.
An optional third parameter is the stride. A negative stride means moving backwards.