Difference between slicing lists with positive and negative indexes?

When we wish to slice from the right side, it’s a matter of using negative index.

array[-2:]

Thanks for the response. The tutorial for that lesson states that you can slice from the right side using positive index. 28%20PM

3 Likes

The example assumes the list is only four elements long. If we add an element, the 2 will need to be a 3. If we use a negative index, we don’t need to change that if more elements are added. It will still give us the last two. Mind, the example does say, ‘the last few’, not the last two.

However, I may be jumping the gun if the concept of negative indices has not come up yet. My apologies if this is racing ahead. Something to keep in mind going forward.

3 Likes