Like cutting a slice from a loaf of bread, lists can be cut into slices. Slicing a list between i and j creates a new list containing the elements starting at index i and ending just before j.
For slicing, a range of indexes has to be given. L[i:j] means create a list by taking all elements from L starting at L[i] until L[j-1]. In other words, the new list is obtained by removing the first i elements from L and taking the next j-i elements .
Here, L[i:] means remove the first elements and L[:i] means take only the first
elements:
L = ['C', 'l', 'o', 'u', 'd', 's'] L[1:5] # remove one element and take four from there: # returns ['l', 'o', 'u', 'd']
You may omit the first or last bound of the slicing:
L = ['C', 'l'...