Python Python Collections (2016, retired 2019) Slices Slice Functions

henry duquesnay
henry duquesnay
6,976 Points

Why does this not work!?!!?!

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

shouldn't this work? Why not? i've tried a million combinations and the only thing that works is when i write the word "iterable" in place of the number values

slices.py
def first_4(1234567)
    return 1234567[0:4]
Tom Finch
Tom Finch
987 Points

You will need a colon at the end of your first line.

1 Answer

Steven Parker
Steven Parker
204,860 Points

Tom's right about needing a colon, but another important syntax rule is that parameter names cannot be entirely digits. It doesn't have to be "iterable", almost any name will do; but it cannot start with a digit.