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

John Schut
John Schut
2,317 Points

Function first_4

My solution is: def first_4(argument): print(argument[:4])

first_4([1,2,3,4,5,6])

But the response is given that a None is returned in stead of [1,2,3,4].

In a seperate Workspace of mine, the same function returns [1,2,3,4]...(?)

What goes wrong?

slices.py
def first_4(argument):
    print(argument[:4])

first_4([1,2,3,4,5,6])

4 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

You are doing it right but the code challenge is asking for you to make a function that returns the first 4 instead of printing them. Do it like this:

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

I hope that helps a little bit

John Schut
John Schut
2,317 Points

Hi Carlos, thanks!

Return vs. print gets me all the time. I've learned to read carefully as a result.

Good luck!

John Schut
John Schut
2,317 Points

Hi Sharon, thanks! Reading is indead a big challenge.... :-)