Python Python Sequences Sequence Operations Slices

Michael McGill
Michael McGill
2,074 Points

Python Tract: Slices video: shouldn't you have said '4' instead of '5'

At 00:35 you said, "and a stop value of '4' means the sliced sequence will end at the fifth element in the sequence" you have seq[1:4] written down and you have 'b', 'c', 'd' highlighted in yellow with 1 2 3 above them. b=1, c=2, d=3

so shouldn't you have said "the sliced sequence will end at the fourth element in the sequence"? or is there a difference between element and index. Would that have been the same as saying "and a stop value of '4' means the sliced sequence will end at the 4th index? This going back and forth between the words index and element is confusing. Is it like this? 0th index = 1st element 1st index = 2nd element 2nd index = 3rd element 3rd index = 4th element 4th index = 5th element

I also heard we have to assume there is an invisible decimal or horizontally splitting line to the left of all the elements/indexes so actually .0, .1, .2, .3, .4, or |0, |1, |2, |3, |4 so we are actually not counting from the number but from the decimal or line. So from the decimal to the left of the 0, it is four hops to the decimal in front of the 4 but we don't include the four hence stop is exclusive because it excludes the element to the right of the decimal and start is inclusive because it includes the element to the right of the decimal?

1 Answer

Treehouse Moderator 17,830 Points

You are correct - element number in this case is referring to the colloquial item in the list, and Python is zero-indexed so index 0 refers to the first element.

As for the second part, I haven't heard it quite that way but that's one way to think about it.

start - starting int where the slice of the object starts

stop - int until which the slice continues, slice stops at index stop - 1

step - int value for the increment between each index (you may not have covered this yet)

Hopefully that helps clarify things, but let me know if you still have questions. I haven't been through this Python course, and it's not my strongest language, but I'll do my best to help. Happy coding!