Slicing and List Methods
Slicing is extracting a portion of a list. We can slice a list by specifying a start index and a stop index, and the result is a subsequence of the items…
Slicing
Slicing is extracting a portion of a list. We can slice a list by specifying a start index and a stop index, and the result is a subsequence of the items contained within the slice.where
• start: index of beginning of the slice (included), default is 0
• stop: index of the end of the slice (excluded), default is the length of the list
• step: increment size at each step, default is 1
List methods
The following is a short list of useful list methods.| Method | What it does |
|---|---|
append(value) | appends value to the end of the list |
insert(index, value) | inserts value at position given by index, shifts elements to the right |
pop(index) | removes object at index from list, shifts elements left and returns removed object. Returns last element if index is omitted. |