I have just completed this lesson on slicing lists, in which it is demonstrated that omitting 0 from the beginning of a slice is perfectly acceptable.
my_list = ['ball', 'hammer', 'wood', 'pin'] #List containing ['ball', 'hammer'] my_list[:2]
But I am slightly confused about selecting elements from the end or lists - particularly, I am wondering if not including an end index in a slice is the same as having the last index be 0…?
For instance, I am curious about the differences between the code blocks below:
suitcase = ['shirt', 'shirt', 'pants', 'pants', 'pajamas', 'books'] #Prints ['pajamas', 'books'] end = suitcase[-2:] print(end)
But when I include zero as the final index, I get an empty list:
suitcase = ['shirt', 'shirt', 'pants', 'pants', 'pajamas', 'books'] #Prints  end = suitcase[-2:0] print(end)
Why might this be?