Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Sequences Sequence Operations Slices

Michael McGill
Michael McGill
2,085 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

rydavim
rydavim
18,813 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!