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

i am stuck in this exercise can anyone help me

giving me a type error

slices.py
def first_4(numbers):
    return(first_4[:5])

1 Answer

Chang Hyun (Bill) Song
Chang Hyun (Bill) Song
3,375 Points

Hey Raj! You've made 2 mistakes. First, you have not used the same parameter- which is, in your case, numbers inside of your parentheses next to def first_4. Instead of writing first_4, replace it with the parameter you have used initially! So, it should be -> def first_4 (numbers): return numbers[:4]

For the 2nd mistake, it's asking for the first 4 items. If we go with [:5], it would be 5 items instead (Remember we count from 0-thus, 0,1,2,3,4). Thus, if we use [:4] instead, it will be (0,1,2,3). Always count from 0. If you're still confused, think of it this way- for instance, if you put [:5], it doesn't mean (1,2,3,4,5), instead it will be (0,1,2,3,4).

Thus, the answer will be def first_4(numbers): return numbers[:4] -> By the way, you do not need to put parentheses around [] when you return value!

Please let me know if you are still confused, I will try my best to explain more!