I'm having trouble understanding why we are allowed say that new_word = new_word[1:len(new_word)], but we aren't allowed to say x = new_word[len(new_word)]. I've tested it by using the following:
print new_word[1:len(new_word)]
print new_word[len(new_word)]

The first one prints fine and the second one has an error. Why is this happening and why isn't the code new_word = new_word[1:len(new_word) - 1]?



This line is asking for an element that does not exist. new_word[len(new_word)] points to the next available element in a list (which is not defined).

This line prints a slice that begins at index 1 (second letter) and includes the full string to the end. It's shortened form looks like this...

print new_word[1:]


Thank you. I think I remember someone saying that when you slice, the lower bound is inclusive but the upper bound is exclusive. Thanks for your response.


So the upper bound is exclusive right?


That is correct; the upper bound is exclusive


A post was split to a new topic: Does anyone know why his isn't working for me?