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

Anthony Ruvinov
PLUS
Anthony Ruvinov
Courses Plus Student 7,638 Points

Please help i dont know what to do

Can someone please help me figure out what's wrong?

slices.py
def first_4(1, 2, 3, 4):
    return first_4[:4]

2 Answers

It seems that you still aren't exactly familiar with defining functions. When defining a function, you should have the parameters in the parentheses, not the arguments themselves (the purpose of a function is to provide it different arguments at different times). Try:

def first_4(iterable):
    return iterable[:4]
Anthony Ruvinov
Anthony Ruvinov
Courses Plus Student 7,638 Points

Oooh, Thanks i was just a bit mixed up with what it was asking me. Thanks for the help!

No problem :)

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Anthony, the method's parameter should be a variable that is iterable. I just call it iterable or whatever works for you. Your slice specification is absolutely correct, but you should slice the parameter (iterable) that you provide to the method.

Look at this:

# iterable is the parameter that the first_4 function expects
def first_4(iterable):
    # slice the parameter and return it
    return iterable[:4]

Does it make sense?