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 Collections (Retired) Slices Slice Functions

Kody Dibble
Kody Dibble
2,554 Points

This is really bugging me...Not sure exactly how to make an iterable...is that just a string?

Slices first step out of three

slices.py
def first_4(iterable)
return iterable[4]

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Kody.

The code you wrote only returns only one element, the element with index 4. What we want here is a slice of the iterable, from element with index 0 up to the 4th element (included).

So the slice would be something like this: [0:4] where you can omit the 0

Vittorio