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 (2016, retired 2019) Slices Slice Functions

yannis sousanis
yannis sousanis
7,199 Points

need help here too...

I see this right but it isnt

slices.py
def first_4(b)

    return b[0:4]

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Yannis,

You've got the right idea - you just left off the colon after your function declaration! Syntax will get you :blush:. Always look for typos first. They trip up everyone.

def first_4(b):
    return b[0:4]

Note you can also leave off the zero at the beginning of a slice:

def first_4(b):
    return b[:4]

Cheers :beers:

-Greg

Ari Misha
Ari Misha
19,323 Points

Hiya Yannis! Try this code for reference :

def first_4(words):
    return words[:4]
Greg Kaleka
Greg Kaleka
39,021 Points

Hi Ari,

Thanks for helping out in the Community. When answering questions, it's always best to give an explanation. Giving students the answers without explanations doesn't help them learn!