Hello, everyone! This is a question about list slicing . It seems simple, but i just don’t understand. When you are slicing a list, why does the final number have to be N+1?
as in: a_list = [2,4]
but you want the third number on the list as the last one? Im confused about this.
I don’t know if any of this will help you, but it does take a little getting used to at first. I found a thread on Stack Overflow where someone asked this question and people chimed in with responses. You might find the discussion and links interesting (or not!).
I think what helped me to grasp the concept is to keep in mind that indexing is zero-based, so the first element in list has index 0, not 1. You get used to it after a while. I think it’s handy when you have to get the first n elements of a list using a_list[:n], which gives you the items at indices 0, 1, 2, … n-1 for a total of n items.