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

Emilio Andere
Emilio Andere
495 Points

I know this is wrong, don't know why! What is missing?

Thank you for every help possible

slices.py
def first_4():
    list1 = ["Emilio", "Soccer", "Love", "Microsoft", "brick"]
    list1[:4]

first_4()

2 Answers

Steven Parker
Steven Parker
231,236 Points

Your function should take an argument, which will be a list, and return the first 4 items from it. You would put a name (perhaps "list1") between the parentheses on the "def" line.

You won't need to create your own list inside the function. You can remove the 2nd line.

And you also only need to define the function, you don't need to call it.

Emilio Andere
Emilio Andere
495 Points

what do you mean by define the function?

Steven Parker
Steven Parker
231,236 Points

The indented code that follows the "def" line defines the function. Putting the function name on a line with parentheses after it invokes (calls) the function, and is not part of the challenge.

Manish Giri
Manish Giri
16,266 Points

Read the instructions again. Your function is provided with an interable, and you need to return the first four items from it -

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

You're instead creating your own list in the function.